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 4 of 4

Thread: get div id

  1. #1
    Regular Coder
    Join Date
    May 2004
    Posts
    391
    Thanks
    76
    Thanked 0 Times in 0 Posts

    get div id

    Hi all!

    If I have div like below how can I alert the div id?

    Code:
    <div id=layer1 >
    
    <a onclick="alertDIV()" href="#" return false; >Click Here alert div</a>
    
    
    
    </div>

  • #2
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    Code:
    <script type="text/javascript">function alertDiv(x){ alert(x); } </script>
    <div id="layer1">
    <a href="javascript:void(0);" onclick="alertDiv(parent.id);">click here</a>
    </div>
    I _think_ this will do it. Get the id of the parent container. Don't forget the quotes around the div's ID.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • Users who have thanked WolfShade for this post:

    nikko50 (09-04-2012)

  • #3
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,990
    Thanks
    56
    Thanked 557 Times in 554 Posts
    Code:
    <body>
    <div id="layer1" >
    <a onclick="alertDIV(this); return false" href="#">Click Here alert div</a>
    </div>
    <script type="text/javascript">
    function alertDIV(el){
    alert(el.parentNode.id)
    }
    </script>
    </body>

  • Users who have thanked xelawho for this post:

    nikko50 (09-04-2012)

  • #4
    Regular Coder
    Join Date
    May 2004
    Posts
    391
    Thanks
    76
    Thanked 0 Times in 0 Posts
    Thanks guys. gOT IT TO WORK!
    Last edited by nikko50; 09-04-2012 at 10:01 PM.


  •  

    Posting Permissions

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