javascript - Show/Hide element when clicking buttons -
i have 2 buttons show , hide , have image want know when click hide button img disappear , when click show button appear again. , don't want css or jquery javascript. if can lot.
window.onload = function(){ var myimg = document.getelementbyid('myimg'); document.getelementbyid('hidebtn').onclick = function(){ myimg.style.display = 'none'; }; document.getelementbyid('showbtn').onclick = function(){ myimg.style.display = ''; }; document.getelementbyid('togglebtn').onclick = function(){ var display = getcomputedstyle(myimg).display=='none'?'':'none'; myimg.style.display = display; }; }
<button id="hidebtn">hide</button> <button id="showbtn">show</button> <button id="togglebtn">toggle</button> <br/> <img id="myimg" src="http://www.eastcottvets.co.uk/uploads/animals/gingerkitten.jpg" alt="" />
Comments
Post a Comment