Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to target image with certain src path with JQuery

Tags:

jquery

attr

src

How would I go about targeting the below img with the src file?

<img src="left1.gif" alt="" />

$('img[src=left1.gif]').hide(); doesn't work

like image 545
Keith Donegan Avatar asked Dec 30 '22 06:12

Keith Donegan


2 Answers

You need to put quotes around the string value of src in your selector. This helps resolves ambiguities with special characters, and seems to apply to the . in the filename.

$("img[src='left1.gif']").hide();
like image 104
zombat Avatar answered Dec 31 '22 19:12

zombat


Your HTML says left1.gif, but your jQuery says lift1.gif. Note also the quotes around my value:

$("img[src='left1.gif']").hide();
like image 41
Sampson Avatar answered Dec 31 '22 20:12

Sampson