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

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

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

**text to change** text t
14条回答
  •  北海茫月
    2020-11-22 08:25

    I think you're looking for .prependTo().

    http://api.jquery.com/prependTo/

    We can also select an element on the page and insert it into another:

    $('h2').prependTo($('.container'));

    If an element selected this way is inserted elsewhere, it will be moved into the target (not cloned):

    Greetings

    Hello
    Goodbye

    If there is more than one target element, however, cloned copies of the inserted element will be created for each target after the first.

提交回复
热议问题