This is the code i used to in coding HTML:
<button id="imageshow" style="display:none">Button1</button>
<button id="imageshow" style="display:none">Button2</button>
<button id="imageshow" style="display:none">Button3</button> <br>
<img src="Images/Image1.jpg" onmouseover="showIt(this.src)"><br>
<button id="imageshow" style="display:none">Button4</button>
<button id="imageshow" style="display:none">Button5</button>
<button id="imageshow" style="display:none">Button6</button>
When i coded this without using style=”display:none”, i am able to add everything fine. But when i coded like above and used the below javascript:
function showIt(imgsrc)
{
document.getElementById('imageshow').src=imgsrc;
document.getElementById('imageshow').style.display='';
}
function hideIt()
{
document.getElementById('imageshow').style.display='none';
}
Only one button is being added. Can anyone resolve this problem. Thank you
You have multiple elements with the same id, so Javascript only takes the first one. Use
class="imageshow"instead and will be ok.The script would look like this: