使用与jQuery.html()链接的jQuery.not()

chi*_*ior 0 jquery chaining

是否可以使用jQuery.not()链式jQuery.html()

winner.not('a').html()
Run Code Online (Sandbox Code Playgroud)

winnerjQuery对象/包装集在哪里,我试图返回删除了锚点的HTML.

gna*_*arf 5

.html() 将返回innerHTML - 其中包含任何A标签,你可能会做这样的事情:

// clone the matched div:
var copy = winner.clone();
// remove all A tags from the DOM
copy.find("a").remove();
// get the html.
var noanchors = copy.html();
Run Code Online (Sandbox Code Playgroud)

另外 - 如果你想让A中的文本仍然存在 - 而不是A本身 - 你可以使用:

// for each A tag
copy.find("a").each(function() {
  //insert the text within ourselves to the document directly before us.
  $(this).before($(this).text());
  // then delete ourselves
  $(this).remove();
});
Run Code Online (Sandbox Code Playgroud)

虽然如果其中<a>包含任何其他标签,实际上可能会有点混乱- 它应该说明这个想法.