Wednesday, August 4, 2010

JQuery: Setting image properties

The following code sets the src and alt attributes for all images



$("img").attr({ src: "test.jpg", alt: "Test Image" });



If you want to det just the src attribute, use:


$("img").attr("src","test.jpg");


If you want to set Title attribute of an image to reflect image filename, use:


$("img").attr("title", function() { return this.src });

No comments:

Post a Comment