If you are trying to change the image source whenever somebody click on it then here is the best way to achieve this. Just two line of code and your headache is gone.
First of all I am taking a HTML image tag and specify a class name for that image tag.
In JQuery find the image tag by its class name, and then assign a onClick event to it.
After assigning OnClick event check the “src” attribute of the tag and then your free to change
that source according to you.
The Image tag is :-
<imgsrc="/images/collapse_1.jpg"alt="xyz"class="ImageOnOff"style="cursor:pointer"/> The JQuery for this is :- $(".imageOnOff").live('click', function () { if ($(this).attr("src").toString().indexOf('collapse_1.jpg') != -1) { this.src = this.src.replace("collapse_1.jpg", "expand_1.jpg"); } else { this.src = this.src.replace("expand_1.jpg", "collapse_1.jpg"); } });