Modifying image source using jQuery click handler

Solution 1: According to Prabu’s answer, the src path is an absolute path rather than a relative path.
Solution 3: Instead of directly attaching the click event, try attaching it to elements and then use jQuery.find(‘img’) to retrieve the thumbnail image’s attribute.


Solution 1:

$('#mty').attr('src', 'http://www.cliparthut.com/clip-arts/1008/paper-stack-clip-art-1008442.jpg');

To ensure correctness, the “src” attribute should be assigned to the img tag and not the div tag.



Solution 2:

Html is as-


Script-


Things to remember-

Execute user script either after rendering HTML or utilizing the jQuery ready function.


Solution 3:





  
    
    
    
    
  

  
   random image
   
   
  

Frequently Asked Questions