HTML/Javascript: Selecting uncles/aunts
        Posted  
        
            by DavidR
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by DavidR
        
        
        
        Published on 2010-05-30T19:07:30Z
        Indexed on 
            2010/05/30
            19:12 UTC
        
        
        Read the original article
        Hit count: 248
        
So I have some code,
<div class="chunk" id="">
    <div class="chunkContent">
        <div class="textLeft" ></div>
        <div class="textRight" ></div>
        <div class="notes border">Notes...</div>
    </div>
    <div class="tools fl">
        <div class="toggleNotes border">n</div>
        <div class="addChunk border">+</div>
    </div>
</div>
Now, the two divs nested withing div.tools are small buttons. div.toggleNotes I need to select div.notes in a javascript/jquery function. div.addChunk I need to select the fisrt div, div.chunk. Currently, I am doing this by:
$(".addChunk").live('click', (function(){create_chunk(this.parentNode.parentNode)}))
$(".toggleNotes").live('click',function(){toggle_notes(this.parentNode.parentNode.firstElementChild.lastElementChild)})
Is there a better (i.e., more proper) way to do this than to string together parentNotes and firstElementChild's and etc.? I'm basically looking around the DOM tab in firebug.
© Stack Overflow or respective owner