jQuery:获取页面的所有html源,但不包括某些#id [英] Jquery: get all html source of a page but excluding some #ids
本文介绍了jQuery:获取页面的所有html源,但不包括某些#id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用.html()或.contents(),但是我有奇怪的行为
I'm trying to use .html() or .contents() but i have strange behaviours
我基本上需要获取页面的整个dom,排除一些元素(例如#first,#second) 并将其作为字符串而不是dom传递...
I basically need to get the entire dom of the page, exclude some elements (ex. #first, #second) and the pass it as a string, not a dom anymore...
有可能吗?
推荐答案
您可以克隆它,从克隆中删除要排除的元素,然后返回克隆的html:
You can clone it, remove the elements you want to exclude from the clone, and then return the clone's html:
$('body').clone().find('#first,#second').remove().end().html()
这篇关于jQuery:获取页面的所有html源,但不包括某些#id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文