Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello guys, i am currently developing a website and currently im stuck at this code
HTML
<div>
                                <img id="tile" src="tilehead1.png"/><br>
                                <img id="hidden2" style="visibility: hidden" src="hide1.png"/><br>
                                <img  önclick="swapImage()" id="readMore" src="ReadMore.jpg"/><img src=".neighbour.png"/><br>
                                <img id="img" src="image1.png"/>
                                </br></br></br>
                                
                            </div>


the above html code is for displating the read more functionality using images, the image for id of"hidden2" is initially hidden but when the user clicks on the image for id "readMore" it switches its "src" attribute value to another image for "done" functionality. the problem is, when the image for id of "hidden 2" is hidden it leaves a huge gap between other images because of the
element before it, i want to be able to add the br element along with the image when a user clicks "readMore"

here is my javaScript code

JavaScript
<script language="Javascript" type="text/javascript">
intImage = 2;
function swapImage() {
switch (intImage) {
 case 1:
   readMore.src = "ReadMore.jpg"
   document.getElementById('hidden2').style.visibility= "hidden";
   intImage = 2
   return(true);
   
   

   
   
case 2:
   readMore.src = "done.png"
   document.getElementById('hidden2').style.visibility= "visible";
   intImage = 1
   return(false);
 }
}
</script>


help me to add the functionality of toggling the
element along with the image that it contains (hidden2), i tried but i failed

Thank you

Posted
Updated 17-Sep-13 0:55am
v2
Comments
Can you see the errors listed in FireBug Console window in FireFox?

1 solution

The code is working fine as far as toggling the image('hidden2') is concerned. However, visibility:hidden css property leaves the space behind. 

So you can go with the display property by which the image space will be removed.

JavaScript
//for hiding
document.getElementById('hidden2').style.display= "none";
//for showing
document.getElementById('hidden2').style.display= "block";

//Also, It is good to refer the 'readMore' image by the document.getElementById() function.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900