Bug Tracker

Opened 11 years ago

Closed 11 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)

test-case-1.html (957 bytes) - added by Maaack 11 years ago.
Example with alerts to show the result of html() on each object.
test-case-2.html (780 bytes) - added by Maaack 11 years ago.
Second test case with Jquery(html) results.

Download all attachments as: .zip

Change History (8)

Changed 11 years ago by Maaack

Attachment: test-case-1.html added

Example with alerts to show the result of html() on each object.

comment:1 Changed 11 years ago by Maaack

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 11 years ago by dmethvin

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?

http://docs.jquery.com/Core/jQuery#expressioncontext

http://docs.jquery.com/Core/jQuery#htmlownerDocument

comment:3 Changed 11 years ago by dmethvin

Component: unfilledselector
Owner: set to john

comment:4 Changed 11 years ago by Maaack

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 11 years ago by Maaack

Attachment: test-case-2.html added

Second test case with Jquery(html) results.

comment:5 Changed 11 years ago by Maaack

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 11 years ago by dmethvin

Resolution: invalid
Status: newclosed

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!

Note: See TracTickets for help on using tickets.