any idea why this JavaScript just shows "block" and not the content of the (hidden) DIV?
<html>
<body>
<div id="mydiv" style="display:none">TEST</div>
<a href="javascript:document.getElementById('mydiv').style.display='block';">Show my DIV</a>
</body>
</html>
I also tried 'inline' but with the same result.
return false/true also failed.
onclick='' also failed.
I know there is style.visibility etc. but i need none/block.
Also the function should work inside the link, i don't want to call an external JS-function.
Thanks!
Because you want to use an onclick event handler, not the href attribute:
<a href="#" onclick="document.getElementById('mydiv').style.display='block';">Show my DIV</a>
jsFiddle example
(side note: inline JavaScript is usually frowned upon)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With