0

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()">
8
  • Try with "Hidden" and "False" in lowercase. Commented Feb 26, 2016 at 1:54
  • Nope, It Didn't work. Commented Feb 26, 2016 at 1:57
  • 1
    Change suit1() to suit(). For some reason having 1 in the function name is causing a problem. Also, change element.setAttribute("Hidden", "False"); To element.hidden=false; Open your browser console, this will display errors. Commented Feb 26, 2016 at 2:03
  • It works fine with that function name fwiw. Commented Feb 26, 2016 at 2:07
  • 1
    Thanks ! The number in suit1() was the problem :) Commented Feb 26, 2016 at 2:09

2 Answers 2

2

Try this:

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

Sign up to request clarification or add additional context in comments.

2 Comments

Nope, Even this does't work. The problem Im getting is not in the javascript. Its that the img is not executing anything onclick
Leave just word hidden in html as well <img src="suit1.png" style="width:100%; height:595px;" hidden id="suit1"/> <img src="point.png" onclick="javascript:suit1()">
2

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.

Comments

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.