attr - Change image source on thumbnail click with jQuery -
I am creating something like a gallery when a large image related to the click on the thumbnail should be loaded.
The way I try to do it is the following:
This is an image tag like this:
The thumbnail is as follows:
& lt; Img src = 'gallery / thumb / [image name]' alt = '' = '[image name]' onclick = 'changePicture ()' /> The name of the thumbnail image and the name of the bigger image are the same and the custom "on" attribute has the same image name, the Change Picture () function is as follows:
< Code> Function Changespace () {var at = $ (this) .attr ('at'); // Thumbnail Vari's get value of "A" attribute on newpath = 'gallery /' +; $ ("#Billitimum"). Att ('src,' Newpath); // Change the "src" attribute of the bigger image} However this function does not work. It seems that I can not get the custom attribute value of "this"
Does anyone help me to understand why this happens?
Thank you.
That's because this is not what you think; In that context, you must pass this to this is window object onclick function: & lt; Img src = "gallery / angus / [image name]" alt = "" = "[image name]" onclick = "change image (this);" / & gt; Change function image (image) {var at = $ (image) .attr ('at'); Var newpath = 'gallery /' +; $ ("#Billitimum"). Att ('src,' Newpath); }
Comments
Post a Comment