Stanimal
Stanimal

Reputation: 15

Enable Javascript function on image click

I had an image which appears on the click of another image.

I'm posting the code below. Please tell me where I went wrong. Thanks !

JavaScript

function suit1() {
  var element = document.getElementById("suit1");
  element.setAttribute("Hidden", "False");
}

HTML

<img src="suit1.png" style="width:100%; height:595px;" hidden="true" id="suit1"/> 
<img src="point.png"  onclick="javascript:suit1()">

Upvotes: 0

Views: 55

Answers (2)

Slartibartfast
Slartibartfast

Reputation: 1583

As stated in the comments, the number in suit1() was causing the issue. However, changing the function name to any name other than the id for first img resolves the problem. HTML:

<img src="suit1.png" style="width:100%; height:595px;" hidden="true" id="suit1"/> 
<img src="point.png"  onclick="javascript:some1()">

JavaScript:

function some1() {
  var element = document.getElementById("suit1");
  element.removeAttribute("hidden");
}

Or change the id of the img.

Upvotes: 2

arnuga3
arnuga3

Reputation: 241

Try this:

 function suit1() {
     var element =     document.getElementById("suit1");
  element.removeAttribute("hidden");
}

Upvotes: 2

Related Questions