jQuery-Dom节点操作

1.  jQuery追加标签

  $('body').append('<h1 style="color: red;" class="c">hello world</h1>')
        $('.c').css('font-size','100px')


2. 移除标签

$('.c').remove()


3. 添加父级标签, 在某个标签的外层添加标签

$('.c').wrap('<div class="p_div"></div>')

4. 在某个标签之前添加标签

$('.c').before('<span>我是before添加的标签</span>')

5. 在某个标签之后添加标签

 $('.c').after('<span>我是after添加的标签</span>')


6. 将某个标签插入到另一个标签之前

 $('<strong>添加到select之前</strong>').insertBefore($('#s'))
        $('<strong>添加到select之后</strong>').insertAfter($('#s'))


7. 去除外层标签

$('.c').unwrap()


8. 标签的隐藏

$('.c').hide()


9. 标签的显示

$('.c').show()


10. 更改标签文本的内容

$('.c').text('xxxxxx')


11. 更改内容的html代码

 $('.c').html('<a href="http://www.baidu.com">百度一下</a>')










猜你喜欢

转载自blog.csdn.net/qq_41664526/article/details/80286719