Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript: style.display:'block' doesn't work

Tags:

javascript

css

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!

like image 271
Roman Tisch Avatar asked Oct 15 '25 16:10

Roman Tisch


1 Answers

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)

like image 184
j08691 Avatar answered Oct 18 '25 05:10

j08691



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!