Jquery Challenge: Child to Parent to Child (brother? or sister?)

Discussion in 'jQuery' started by jackburd, Oct 10, 2011.

  1. #1
    Hi I need help regarding this.

    I have this code for example

    <div class="item">
    	<a href="#">Link 1</a>
    	<div class="hidden">content here</div>
    </div>
    
    <div class="item">
    	<a href="#">Link 2</a>
    	<div class="hidden">content here</div>
    </div>
    
    <div class="item">
    	<a href="#">Link 2</a>
    	<div class="hidden">content here</div>
    </div>
    HTML:
    Now, I want that when I click a link, the div class="hidden" will pop up.

    My only concern is, how am I going to call the div class relative to my anchor text.

    It's like calling the child which is a brother or sister? :)
     
    jackburd, Oct 10, 2011 IP
  2. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,564
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #2
    The nextSibling object.

    This is your CSS:

    
    .hidden{
         display:none;
    }
    
    Code (markup):
    Your Javascript:
    
    function showContent(link){
        link.nextSibling.nextSibling.style.display='block';
    }
    
    Code (markup):
    Your HTML for a link:
    
    <a href="#" onclick="showContent(this)">Link 1</a>
    <div class="hidden">Hidden Content</div>
    
    Code (markup):
     
    blueparukia, Oct 10, 2011 IP
  3. jackburd

    jackburd Active Member

    Messages:
    396
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    73
    #3
    it works! thanks man!

    i just need to convert it to jquery to make it more sophisticated :)
     
    jackburd, Oct 10, 2011 IP
  4. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,564
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #4
    You mean less efficient?
     
    blueparukia, Oct 10, 2011 IP
  5. myst_dg

    myst_dg Active Member

    Messages:
    224
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    58
    #5
    $('a').click(function() {
    $(this).next().show();
    return false;
    });
     
    myst_dg, Oct 23, 2011 IP
  6. myst_dg

    myst_dg Active Member

    Messages:
    224
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    58
    #6
    your code is not cross-browser compatible......
     
    myst_dg, Oct 23, 2011 IP