我正在尝试删除处于非事件状态的 li,但无法使其工作:
var html = $("#myjqgriddiv").remove("ul li:not(.ui-state-active)").html();
我有html,我想删除不包含类.ui-state-active
的li
在 li 上方的代码之后,.ui-state-active 仍然存在。
需要帮助。
更新:
我打算使用 window.open("","Print")/document.write 打印 html
@tvanfosson 答案有效,但还有一点小事情,第一次修改后留下的单个 li 我也想编辑,我想从其 a
子元素中删除属性“href”
var html = $('#myjqgriddiv') // select div
.find('ul li:not(.ui-state-active)') // select elements to remove from div
.remove() // remove the matched elements
.end() // revert back to the originally selected elements
.html(); // and get the HTML
html = $(html).find("ul li.ui-state-active a)").removeAttr("href").html(); // not working?!
最佳答案
remove 的参数充当过滤器,而不是选择器。由于您只选择了 id mygqgriddiv
的一个元素,因此过滤器不会删除任何内容。尝试一下。
var html = $('#myjqgriddiv') // select div
.find('ul li:not(.ui-state-active)') // select elements to remove from div
.remove() // remove the matched elements
.end() // revert back to the originally selected elements
.find("ul li.ui-state-active a)") // now get the active ones
.removeAttr("href") // remove the href attribute
.end() // back to the original selection
.html(); // and get the HTML
关于jquery - 删除不包含特定类的html元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7375614/