I have a list of li tags with an image. When a user clicks a particular link i want to change the image. When a user clicks a new li tag then the last li tag should reset. I done everything except to set a new image for the particular li tag. And the major problem is i’m not passing any arguments to the function.
$(document).ready(function(){
$(".sized ul li a").click(function(){
$('.sized ul li a img').each(function(){$(this).remove(); }); // Removing all images
$('.sized ul li a ').each(function(){$(this).append('<img src="1.png" />'); });// Reset the images
});
I don’t understand why it is a problem to not pass any arguments.
Instead of removing and adding a new image for all links, just change the one that was clicked before. You can change the image by just changing its
srcattribute with.attr():