Jquery selector for <link> elements in <head>

前端 未结 4 722
囚心锁ツ
囚心锁ツ 2020-12-30 06:06

We use jQuery to parse some HTML. I then need to traverse that document and find some elements. Among the elements I need to find, there are the el

4条回答
  •  情歌与酒
    2020-12-30 06:42

    Like @pimvdb pointed, this don't work:

    alert($("
    Test
    ").find("link").text());

    The explanation is right:

    Sizzle uses context.getElementsByTagName, which fails because the elements are not in the DOM.

    But this way work:

    alert(("link", $("
    Test
    ")).text());

    And for some guys that said the second isn't working: http://jsfiddle.net/ErickPetru/5Qs3M/. But of course it obviously don't find elements that aren't on the DOM (i.e. on the head).

提交回复
热议问题