Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Aug 2008
    Posts
    60
    Thanks
    6
    Thanked 6 Times in 6 Posts

    Question Onclick dissapear

    I have the following code...
    Code:
    <center>Shoot an "A"</center>
    <div class="shoot"><span onclick="alert('Miss');">BTEHJD</span>
    <span id="a" onclick="alert('Hit');">A</span>
    <span onclick="alert('Miss');">GDHJD</span>
    <span id="b" onclick="alert('Hit');">A</span>
    <span onclick="alert('Miss');">KBFKBM<br>B</span>
    <span id="c" onclick="alert('Hit');">A</span>
    <span id="d" onclick="alert('Hit');">A</span>
    <span id="e" onclick="alert('Hit');">A</span>
    <span onclick="alert('Miss');">BGDJJVB</span>
    <span id="f" onclick="alert('Hit');">A</span>
    <span onclick="alert('Miss');">G</span>
    <span id="g" onclick="alert('Hit');">A</span>
    <span onclick="alert('Miss');">HDJNJJ<br>HDFGBJVBKJGVJG</span>
    <span id="h" onclick="alert('Hit');">A</span>
    <span onclick="alert('Miss');">HFGTR</span>
    </div>
    <style>.shoot{
     cursor: crosshair;
     height: 75px;
     width: 200px;
     BORDER: solid 2px grey;}
    </style>
    Can I make the A's Disapear Onclick

  • #2
    Regular Coder ninnypants's Avatar
    Join Date
    Apr 2008
    Location
    Utah
    Posts
    504
    Thanks
    10
    Thanked 47 Times in 47 Posts
    just add this after your alerts on all of your 'hit's
    Code:
    this.display='none'
    if you want a reset you need to loop through all of the elements and set their display back to normal

  • #3
    New Coder
    Join Date
    Aug 2008
    Posts
    60
    Thanks
    6
    Thanked 6 Times in 6 Posts
    how do you do that?Sorry I am very New

  • #4
    Regular Coder ninnypants's Avatar
    Join Date
    Apr 2008
    Location
    Utah
    Posts
    504
    Thanks
    10
    Thanked 47 Times in 47 Posts
    Code:
    <span id="d" onclick="alert('Hit');this.display='none';">A</span>

  • #5
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,338
    Thanks
    29
    Thanked 282 Times in 276 Posts
    Quote Originally Posted by ninnypants View Post
    Code:
    <span id="d" onclick="alert('Hit');this.display='none';">A</span>
    Actually, that would be this.style.display = 'none'; rather than this.display = 'none';.

    Additionally:
    • If one wanted to hide elements without affecting the surrounding layout, one would use this.style.visibility = 'hidden';.
    • If one had no further use for these elements, they could be removed entirely via this.parentNode.removeChild(this);.
    For every complex problem, there is an answer that is clear, simple, and wrong.

  • #6
    SSJ
    SSJ is offline
    Regular Coder
    Join Date
    Mar 2007
    Posts
    230
    Thanks
    0
    Thanked 4 Times in 4 Posts
    That's Perfect and I will prefer that "this.parentNode.removeChild(this);" method if it is not needed anymore.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •