SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    966
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    strange. element not hiding itself onclick

    Hello,

    i have a div dynamically created on page load using php. the id is 'A'.
    When click on 'A' , another div is shown. Name is 'B'. this div is a child div of 'A'.

    now 'B' div has onclick hide('B').
    But when i click it does not hide itself. strage. but if i put another element name for example 'A', Then it works.

    why 'B' is not hiding itself while it hideS any other element on that page including it's parent 'A'?

    Code:
    function hide(name){
    	document.getElementById(name).style.display='none';
    }
    function show(name){
    	document.getElementById(name).style.display='block';
    }

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,940
    Mentioned
    215 Post(s)
    Tagged
    12 Thread(s)
    Hi,

    Can you post a link to a page where I can see this not working?

  3. #3
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    966
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Pullo View Post
    Hi,

    Can you post a link to a page where I can see this not working?
    i just pm'd you the link pullo..

  4. #4
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,940
    Mentioned
    215 Post(s)
    Tagged
    12 Thread(s)
    Hi,

    the problem is the id attribute.

    You have:

    HTML Code:
    <div class="marker" id="1marker" onclick="hide('1marker')"></div>
    An id may not begin with a number. Change it to id="markerOne" or something similar.

    HTH

  5. #5
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    966
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Pullo View Post
    Hi,

    the problem is the id attribute.

    You have:

    HTML Code:
    <div class="marker" id="1marker" onclick="hide('1marker')"></div>
    An id may not begin with a number. Change it to id="markerOne" or something similar.

    HTH
    Just tried by putting the number to back, but result is same
    any way, now i do not require it be hidden on click. the plan is bit changed.

    Thank you.

  6. #6
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,940
    Mentioned
    215 Post(s)
    Tagged
    12 Thread(s)
    Strange!

    This will definitely work as expected:

    Code:
    <div class="marker" id="marker" onclick="hide('marker')">Click me to hide</div>
    
    <script>
    function hide(name){
      document.getElementById(name).style.display='none';
    }
    </script>
    so I guess there was something else going on.

  7. #7
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    966
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Pullo View Post
    Strange!

    This will definitely work as expected:

    Code:
    <div class="marker" id="marker" onclick="hide('marker')">Click me to hide</div>
    
    <script>
    function hide(name){
      document.getElementById(name).style.display='none';
    }
    </script>
    so I guess there was something else going on.
    Strange strange
    JQUERY LIVE CLICK was hiding finally

    Thank Pulli for your valuable time!


Bookmarks

Posting Permissions

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