any idea why this JavaScript just shows \"block\" and not the content of the (hidden) DIV?
The value of the javascript expression
document.getElementById('mydiv').style.display='block'
is the string 'block'
- think of the way you can do a=b='something'
- in javascript the value of an assignment expression is the assigned value.
If you try
link
You'll find clicking the link navigates to a document containing just the word howdy
- and the same thing is happening with your code. You can stop this happening by adding an explicit void(0)
, or by wrapping the code in an immediately-invoked function expression that doesn't return a value (i.e. implicitly returns undefined
), so:
(This structure is commonly used in bookmarklets). However, as several comments have already pointed out, in general the use of javascript:
hrefs is frowned upon, and you should consider using event handling instead.