i am making a little project with simple hmtl and jquery, and i’m expecting difficult right at the moment with that issue : over the html i have simple images like this:
<img src="color.png" alt="color" width="44" height="46" />
<img src="gray.png" alt="gray" width="44" height="46" />
but sometimes the alts are identical, so i want to make a “check function” in jquery that compares and checks the alts of the images and if they are equal to execute an alert. I come to here but it don’t work
jQuery(document).ready(function(){
var grayBall = $("img[alt*='gray']");
var colorBall = $("img[alt*='color']");
if(colorBall.attr('alt') = grayBall.attr('alt')){
alert("They are matching !");
};
});
everything like adding the jquery to the html is ok only this function don’t work.
Try using
==(equality) instead of=(assignment)Update Have you tried this? Change the alt tag of one img and also change the selector in your script: