Ryan
Ryan

Reputation: 499

What's wrong with this Javascript code?

<a href="javascript:document.getElementById('create_table').style.display='block'">Insert Table</a>

The code works perfectly fine in Google Chrome but in Internet Explorer and Firefox it just redirects to a page with the text "block"

Upvotes: -1

Views: 126

Answers (2)

Gumbo
Gumbo

Reputation: 655209

Your qoutes are wrong:

javascript:document.getElementById('create_table').style.display=''block

It must be:

javascript:document.getElementById('create_table').style.display='block'

But you shouldn’t use javascript: pseudo-protocol anyway. Better use JavaScript to only enrich your document.

Upvotes: 4

BalusC
BalusC

Reputation: 1108682

You should never use the javascript: pseudoprotocol. Use the click event for this. Besides, also watch the quotes.

Here's the correct approach:

<a href="#" onclick="document.getElementById('create_table').style.display='block'; return false;">Insert Table</a>

Note that I (optionally) returned false here to block the default action.

Upvotes: 4

Related Questions