facebook

Change color of a specific word in text string

  1. MobiOne Archive
  2.  > 
  3. Getting Help – General
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #339581 Reply

    davidg
    Member

    Hi,

    I am trying to change the color of just one word in text string but I am not sure if that is possible.

    Here is a few examples:

    
    var word1
    word1 = 'Blue Text'
    word1.fontcolor("#0EBFE9") // change color of string to blue
    $('#m1-project-text1').text('Sample text in black color'+word1);
    

    Now I know this code doesn’t work and I think it is because the css properties can only change the entire text div and don’t affect the values in the object But is there any other way of doing this without making two different text objects?

    #339582 Reply

    Stu Wade
    Member

    No.

    Or, to be fair, I do not believe so.

    #339584 Reply

    Brandon
    Member

    You can do something like this if you use the HTML widget…

    #339586 Reply

    davidg
    Member

    @CincyPlanet wrote:

    You can do something like this if you use the HTML widget…

    Hey thanks CincyPlanet!
    That pointed me in the right direction and I got it figured out.

    Just in case anyone needs to reference this ever, here is how I did it.

    I put HTML widget on the page and declared the following div inside it:

    <div id=”output”></div>

    then I used the following code in custom.js and it worked great

    
    
    var output = document.getElementById('output');
    var word1
    
    word1 = 'Blue Text'
    word1.fontcolor("#0EBFE9") // change color word1 string to blue
    var str = 'Sample text in black color' + word1; 
    
    output.innerHTML = str;
    

    Thanks guys for posting

    #339590 Reply

    Stu Wade
    Member

    Thanks, CincyPlanet, I would never have thought to use the HTML widget.

    #339594 Reply

    Brandon
    Member

    No problem.

Viewing 6 posts - 1 through 6 (of 6 total)
Reply To: Change color of a specific word in text string

You must be logged in to post in the forum log in