1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
---|
2 | <html lang=en> |
---|
3 | <head> |
---|
4 | <title>jquery attribute selectors - style</title> |
---|
5 | <style type="text/css"> |
---|
6 | div { |
---|
7 | padding: 1em; |
---|
8 | margin: 0 1em 1em 0; |
---|
9 | float: left; |
---|
10 | } |
---|
11 | p { |
---|
12 | clear: left; |
---|
13 | } |
---|
14 | div, div.nostyle.found { background: #f00 } |
---|
15 | div.found, div.nostyle { background: #0f0 } |
---|
16 | </style> |
---|
17 | <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script> |
---|
18 | <script type="text/javascript"> |
---|
19 | $(function() { |
---|
20 | $('div[style]').addClass('found').html('OK'); |
---|
21 | $('div.nostyle.found').html('FAIL'); |
---|
22 | }); |
---|
23 | </script> |
---|
24 | </head> |
---|
25 | <body> |
---|
26 | <div style="">FAIL</div> <!-- empty-string attr: should match --> |
---|
27 | <div style="float:left">FAIL</div> <!-- non-empty attr: should match --> |
---|
28 | <div class=nostyle>OK</div> <!-- no attr: should not match --> |
---|
29 | <p>There should be three green boxes saying "OK"</p> |
---|
30 | </body> |
---|
31 | </html> |
---|