Side navigation
#4019 closed bug (invalid)
Opened January 29, 2009 02:19AM UTC
Closed February 01, 2009 02:45AM UTC
Inconsistent selector behavior when selecting from a subset of html text or Jquery object
Reported by: | Maaack | Owned by: | john |
---|---|---|---|
Priority: | major | Milestone: | 1.3.2 |
Component: | selector | Version: | 1.3.1 |
Keywords: | selector subset | Cc: | |
Blocked by: | Blocking: |
Description
When using a selector in the form of $("element",html), the behavior is different depending on whether the html variable is a JQuery object or the innerHtml of that JQuery object. So that:
var html = $("html");
$("div", html);
and
var html = $("html").html();
$("div", html);
will return two different results. The div returned from the second example will have to be nested in two (Why two?) other elements in order to be recognized or else null will be returned.
Attachments (2)
Change History (6)
Changed January 29, 2009 04:57AM UTC by comment:1
Changed January 30, 2009 12:46AM UTC by comment:2
Are you trying to use a string as the second argument to the jQuery() constructor? I don't see anywhere that is allowed. Or did I misinterpret something?
Changed January 30, 2009 01:11AM UTC by comment:3
component: | unfilled → selector |
---|---|
owner: | → john |
Changed January 30, 2009 04:39AM UTC by comment:4
Apologies. I am getting strange behavior from jQuery(html, [ownerDocument]) when loading html via AJAX and I generalized it to this. I see that the function will not create <html> or <body> elements, but I'm still getting inconsistent results. I'll look into it some more.
Changed January 30, 2009 05:43AM UTC by comment:5
The file I just attached is what I am having trouble getting my head around. I could not find any documentation explaining why
var html = $("html").html();
alert($(html).html());
would return "undefined" when creating something very similar to a typical html document directly with a string and passing it over to the jQuery object would simply ignore the <html> and <body> tags and work with the tags nested in them.
Changed February 01, 2009 02:45AM UTC by comment:6
resolution: | → invalid |
---|---|
status: | new → closed |
The
.html()method, like the
.innerHTMLproperty of a DOM node, does not return the HTML for the node where you use the method/property.
The bug tracker isn't a good place for discussion threads. If you're unsure of how jQuery works, ask on one of the forums first. If the consensus is that whatever you're seeing is really a bug, post a clear test case here. Thanks!
Sorry this should be filed under the component selector. Also null is not returned in the second case, but an empty object that returns null when html() is called on it.