views:

78

answers:

5
<IMG height="160" alt="Web Content Image" src="../image/journal/article?img_id=16505&t=1273484793531" width="240" pngSet /> 

I have the this code for the image , and I want to select the image based on the attribute "pngSet"

I am trying this , but not working.

$("img[pngSet='']").css('border' ,'1px solid red');
+4  A: 

You can do it like this:

 $("img[pngSet]").css('border' ,'1px solid red');

The has attribute selector is just [attributeName] :)

Nick Craver
I am curious as to why it didn't match though. http://jsbin.com/adida4 works.
wombleton
@wombleton - It's not guaranteed to cross-browser though, I can't recall which ones it fails on, but there are a few, or at least used to be.
Nick Craver
+3  A: 

Should be:

$('img[pngSet]')
wombleton
A: 
$("img[pngSet]");
sundowatch
A: 

It's usually a bad idea to make up attributes. Browsers don't have to support it. Best would be to use a class instead:

<IMG height="160" alt="Web Content Image" src="../image/journal/article?img_id=16505&t=1273484793531" width="240" class="pngSet" /> 
$("img.pngSet").css('border' ,'1px solid red');
RoToRa
+1  A: 

Give this a shot (using the has attribute selector):

$("img[pngSet]")
GlenCrawford