Change last letter color

后端 未结 8 1568
隐瞒了意图╮
隐瞒了意图╮ 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 16:59

    In what way do you "display the string letter by letter"? If you're looping through the characters in a string (variable) you can certainly tell when you're at the last letter and wrap it in a whether doing so on the server side or client side.

    Looking at the fiddles attached to another of your questions ...

    If this is what you're talking about, you might have to set the .innerHTML of the element instead of the element.text()

    From the fiddle at http://jsfiddle.net/SLKEn/ you would change it to something like this

    if(current < contentArray.length) {
        elem.html(
                elem.html() +
                  (current == contentArray.length-1 ?
                   '' + contentArray[current++] + '' :
                   contentArray[current++])
                 );
            }
    

    along with CSS span.lastchar { color: red; }


    Update: working fiddle based on your other question.

提交回复
热议问题