Skip to main content

Bug Tracker

Side navigation

#2787 closed bug (fixed)

Opened May 05, 2008 05:16AM UTC

Closed May 06, 2008 02:31AM UTC

Attribute filter ignores elements not appended to DOM tree

Reported by: arrix Owned by:
Priority: major Milestone: 1.2.4
Component: core Version: 1.2.3
Keywords: selector Cc:
Blocked by: Blocking:
Description

Attribute filter ([attribute=value]) cannot select elements not appended to the document tree.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>1.2.4a Rev: 5390</title>
		<script type="text/javascript" src="../jquery/dist/jquery.js"></script>
		<script type="text/javascript">
			$(function() {
				var f = $('<form><input type="button" name="ok" value="OK"/></form>');
				alert(f.find('input[name="ok"]').length); //0 but should be 1
				f.appendTo(document.body);
				alert(f.find('input[name="ok"]').length); //1
			});
		</script>
	</head>
	<body>
	</body>
</html>

1.2.4a Rev: 5390

Attachments (0)
Change History (3)

Changed May 05, 2008 05:37AM UTC by arrix comment:1

It's in selector.js jQuery.filter (near line 338)

// special case, filter by exact name
if ( !not && m[2] == 'name' && type == '=' )
	r = jQuery.grep( document.getElementsByName(m[5]), function(elem){
		return jQuery.inArray( elem, r ) != -1;	
	});

of course document.getElementsByName only returns elements in the document tree.

Changed May 05, 2008 05:59AM UTC by arrix comment:2

Changed May 06, 2008 02:31AM UTC by flesler comment:3

resolution: → fixed
status: newclosed

Fixed, check #1960 for more details.