-1

My Javascript code is giving syntax error, I am unable to find where is the problem:

<script type="text/javascript">
   function display(id,type){
    alert("Hi");    
   }
</script>

onclick event is given below:

<map name="Map" id="Map">
  <area shape="rect" coords="24,165,133,182" href="#" onclick="display("#td1","show")" />
  <area shape="rect" coords="23,190,167,209" href="#" />
  <area shape="rect" coords="23,218,165,235" href="#" />
  <area shape="rect" coords="22,242,165,261" href="#" />
  <area shape="rect" coords="23,268,164,286" href="#" />
</map>
5
  • 5
    onclick="javascript:display("#td1","show")". Check your quotes. Commented Mar 3, 2014 at 17:00
  • 5
    ("#td1","show") change those to single quotes. Commented Mar 3, 2014 at 17:00
  • convert the onclick event to onclick="display('#td1','show');" Commented Mar 3, 2014 at 17:03
  • Single quotes. The problem is that by using " several times, the browser thinks you are opening and closing several different quotes. "diplay(", #td1(which causes the syntax error), ",", show, and ")". Commented Mar 3, 2014 at 17:05
  • can you show your td html as well? Commented Mar 3, 2014 at 17:12

1 Answer 1

2

change quote to single quote

<area shape="rect" coords="24,165,133,182" href="#" onclick="javascript:display('#td1','show')" />
Sign up to request clarification or add additional context in comments.

2 Comments

Now I am getting below in firebug: TypeError: document.getElementById(...) is null document.getElementById(id).style.display="inline";
remove # from id, because # is jquery id selector, you are using nativa javascript ... display('td1','show') />

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.