Skip to main content

Bug Tracker

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)
  • test-case-1.html (0.9 KB) - added by Maaack January 29, 2009 02:21AM UTC.

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

  • test-case-2.html (0.8 KB) - added by Maaack January 30, 2009 05:33AM UTC.

    Second test case with Jquery(html) results.

Change History (6)

Changed January 29, 2009 04:57AM UTC by Maaack comment:1

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.

Changed January 30, 2009 12:46AM UTC by dmethvin 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?

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

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

Changed January 30, 2009 01:11AM UTC by dmethvin comment:3

component: unfilledselector
owner: → john

Changed January 30, 2009 04:39AM UTC by Maaack 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 Maaack 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 dmethvin comment:6

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!