Thursday, 20 March 2014

jquery check src of image

Some time we have to do the operation based on image operation on that case need to check the image SRC, what is it, like toggle the div open and 
close also we need to check the image src.
There is the simple way to achieve to check the src of image is;

@HTML Code
<img alt="top" src="\images\up.jpg" />
    <img  alt="down" src="\images\down.jpg" /> 

@Jquery code to check SRC
  var src = $('img[alt="top"]').attr('src');
        alert("image with alternate text = top image - " + src);
        var srcAll = $('img[alt="down"]').attr('src');
        alert("image with alternate text = down image - " + srcAll);

No comments:

Post a Comment