Reputation: 3427
This will run when the page loads
<TD width=115 >
<a href="#" onclick="some functions"> Expand All</a>
</TD>
<TD align=left>
<a href="#"><IMG id="img1" border=0 alt="" src="expand.png">12345 </a>
</TD>
By default, expand.png image will be displayed with 12345.. My question is If I click expand all link, I need to change the image "expand.png" to "collapse.png"..Is it possible in javascript?
Upvotes: 0
Views: 87
Reputation: 180
Does it need to be pure JS?
Jquery:
$('#button').click(function(){
$('#withImage').attr('src', 'collapse.png');
});
You would have to give the TD's a class or an ID
pure JS:
document.getElementById('button').onClick(runFunction());
function runFunction(){
document.getElementById('withImage').src = 'collapse.png';
}
First line of code is telling the script that when a tag with the id "button" (
In the function you are telling the script that the tag with id "withImage" should change its attribute "src" to be 'collapse.png'.
Upvotes: 4
Reputation: 90
Just add below code to your function of Expand All, if its Jquery
$('#img1').attr('src', 'collapse.png');
Upvotes: 0
Reputation: 567
I think this will solve your issue.
<a href="#" onclick="document.getElementById('img1').src='collapse.png'">Expand All</a>
<a href="#"><IMG id="img1" border=0 alt="" src="expand.png">12345</a>
JSfiddle: http://jsfiddle.net/zJ85X/
Upvotes: 2
Reputation: 2048
You can use this:
<TD width=115 >
<a href="#" onclick="expand()"> Expand All</a>
</TD>
<TD align=left>
<a href="#"><IMG id="img1" border=0 alt="" src="expand.png">12345 </a>
</TD>
<script>
function expand(){
$('#img1').attr('src','collapse.png');
}
</script>
Upvotes: 0