I have some images, all of which have alt tags.
I am trying to add a class to all of the images which have a certain alt tag.
So to put it in plain terms:
If image alt
tag = "dog" then add class "canine"
Any ideas?
thanks
I have some images, all of which have alt tags.
I am trying to add a class to all of the images which have a certain alt tag.
So to put it in plain terms:
If image alt
tag = "dog" then add class "canine"
Any ideas?
thanks
Share Improve this question edited Dec 7, 2010 at 14:24 Gabriele Petrioli 196k34 gold badges271 silver badges328 bronze badges asked Dec 7, 2010 at 14:22 TomTom 13k50 gold badges153 silver badges247 bronze badges3 Answers
Reset to default 11You can use the attribute equals selector and addClass method:
$("img[alt='dog']").addClass("canine");
or you can use
$("img[alt*='dog']").addClass("canine");
to include any image with alt Containing dog
.
$('img[alt="dog"]').addClass("canine")
it's realy easy...
notetoself: type faster... ;)