Opened 14 years ago
Closed 14 years ago
#4019 closed bug (invalid)
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 (8)
Changed 14 years ago by
Attachment: | test-case-1.html added |
---|
comment:1 Changed 14 years ago by
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.
comment:2 Changed 14 years ago by
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?
comment:3 Changed 14 years ago by
Component: | unfilled → selector |
---|---|
Owner: | set to john |
comment:4 Changed 14 years ago by
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 14 years ago by
Attachment: | test-case-2.html added |
---|
Second test case with Jquery(html) results.
comment:5 Changed 14 years ago by
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.
comment:6 Changed 14 years ago by
Resolution: | → invalid |
---|---|
Status: | new → closed |
The .html()
method, like the .innerHTML
property 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!
Example with alerts to show the result of html() on each object.