Change last letter color

后端 未结 8 1573
隐瞒了意图╮
隐瞒了意图╮ 2020-11-27 16:42

Example code:

string

I want to change the color on the last letter, in this case \"g\", but I need soluti

8条回答
  •  生来不讨喜
    2020-11-27 17:12

    Without using javascript, your only option is:

    string

    Edit for your fiddle link:

    I'm not really sure why you said you didn't need a javascript solution, since you have quite a bit of it already. Regardless, in this example, you need to make only a couple small changes. Change line 10 from

    elem.text(elem.text() + contentArray[current++]);
    

    to

    if ( current == contentArray.length-1 ) {
        elem.html(elem.html() + ""+contentArray[current++]+"");
    } else {
        elem.html(elem.html() + contentArray[current++]);
    }
    

    Note that it's important to use .html() instead of .text() now, since there's actually HTML markup being inserted.

    Working fiddle: http://jsfiddle.net/QTUsb/2/

提交回复
热议问题