Tejas Kanani
Tejas Kanani

Reputation: 133

How to select the IMG tag based on the attribute?

<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');

Upvotes: 0

Views: 1744

Answers (5)

GlenCrawford
GlenCrawford

Reputation: 3389

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

$("img[pngSet]")

Upvotes: 1

RoToRa
RoToRa

Reputation: 38431

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');

Upvotes: 0

sundowatch
sundowatch

Reputation: 3103

$("img[pngSet]");

Upvotes: 0

wombleton
wombleton

Reputation: 8376

Should be:

$('img[pngSet]')

Upvotes: 3

Nick Craver
Nick Craver

Reputation: 630549

You can do it like this:

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

The has attribute selector is just [attributeName] :)

Upvotes: 4

Related Questions