Bug Tracker

Opened 10 years ago

Closed 9 years ago

Last modified 8 years ago

#6044 closed bug (duplicate)

$("selector[style='value']", context) does not work

Reported by: jide Owned by: john
Priority: undecided Milestone: 1.4.2
Component: selector Version: 1.4.1
Keywords: Cc:
Blocked by: Blocking:

Description

See the following code :

<!DOCTYPE html PUBLIC "-W3CDTD XHTML 1.1EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html>

<head>

<title>Test jQuery</title> <style type="text/css"> </style> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script> <script type="text/javascript">

$(document).ready(function() {

var container = $('#container'); Works : console.log($("div[style='font-size:2em']").html()); Does not work : console.log($("div[style='font-size:2em']", container).html());

});

</script>

</head> <body>

<div id="container">

<div style="font-size:2em">

A test div.

</div>

</div>

</body>

</html>

Change History (8)

comment:1 Changed 10 years ago by jide

Arghh, there is no way to edit the ticket and I forgot code formatting !

Here we go :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
	<head>
		<title>Test jQuery</title>
		<style type="text/css">
		</style>	
		<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
		<script type="text/javascript">
			$(document).ready(function() {
				var container = $('#container');
				// Works :
				console.log($("div[style='font-size:2em']").html());
				// Does not work :
				console.log($("div[style='font-size:2em']", container).html());
			});
		</script>
	</head>
	<body>
		<div id="container">
			<div style="font-size:2em">
				A test div.
			</div>
		</div>
	</body>
</html>

comment:2 Changed 10 years ago by jide

Hmmm, this is a better example :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
	<head>
		<title>Test jQuery</title>
		<style type="text/css">
		</style>	
		<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
		<script type="text/javascript">
			$(document).ready(function() {
				var container = $('#container');
				// Works :
				console.log($("div[style*='background']").html());
				// Does not work :
				console.log($("div[style*='background']", container).html());
			});
		</script>
	</head>
	<body>
		<div id="container">
			<div style="background:red" class="mydiv">
				A test div.
			</div>
		</div>
	</body>
</html>

comment:3 Changed 10 years ago by john

Component: ajaxselector
Owner: set to john
Status: newassigned
Summary: $("selector[attr='value']", context) does not work$("selector[style='value']", context) does not work

comment:4 Changed 9 years ago by jide

I found a way to fix this :

Edit Sizzle.selectors.filter.ATTR (line 3273 in jquery v1.4.2), and change line 3277 :

elem[ name ] != null && name != 'style' ?

This will treat the style attribute as a regular attribute.

comment:5 Changed 9 years ago by jide

I committed this fix on my github fork and made a pull request.

comment:6 Changed 9 years ago by snover

Priority: undecided
Resolution: duplicate
Status: assignedclosed

Duplicate of #3399.

comment:8 Changed 9 years ago by anonymous

<a href="http://www.charmforbracelets.com">charm for bracelets</a>delicate and high-profile in its own way. All of these ornaments manifest a postmodernism pattern and brought us strong visual shock impact.Also you can change your cloth a<a href="http://www.charmforbracelets.com">charms for links of London</a>clothe pattern. <a href="http://www.charmforbracelets.com">charm for bracelets</a>

Note: See TracTickets for help on using tickets.