Ticket #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: | ||
| Blocking: | Blocked by: |
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
comment:2 Changed 3 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 3 years ago by john
- Owner set to john
- Status changed from new to assigned
- Component changed from ajax to selector
- Summary changed from $("selector[attr='value']", context) does not work to $("selector[style='value']", context) does not work
comment:4 Changed 3 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 3 years ago by jide
I committed this fix on my github fork and made a pull request.
comment:6 Changed 3 years ago by snover
- Priority set to undecided
- Status changed from assigned to closed
- Resolution set to duplicate
Duplicate of #3399.
comment:8 Changed 2 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>
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

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>