How can I change an element's text without changing its child elements?

前端 未结 14 2090
难免孤独
难免孤独 2020-11-22 07:30

I\'d like to update element\'s text dynamically:

**text to change** text t
14条回答
  •  无人及你
    2020-11-22 08:23

    Just wrap the text you want to change in a span with a class to select.

    Doesn't necessarily answer your question I know, but, probably a better coding practice. Keep things clean and simple

    
    

    Voilà!

    $('#header .mytext').text('New text here')
    

提交回复
热议问题