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

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

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

**text to change** text t
14条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-22 08:06

    See In action

    Markup :

    $(function() {
      $('input[type=button]').one('click', function() {
        var cache = $('#parent').children();
        $('#parent').text('Altered Text').append(cache);
      });
    });
    
    
    Some text
    Child1
    Child2
    Child3
    Child4

提交回复
热议问题