How to select a outer outer div???

Discussion in 'jQuery' started by WillPooleDesigns, Jun 18, 2014.

  1. #1
    <div>
    <a>
    <img>
    </a>
    <p></p>
    </div>
    ---------------
    <div>
    <a>
    <img>
    </a>
    <p></p>
    </div>
    ----------------

    All I want to do is using the img tag selected as $(this) to select the contents of <p> tag in the outer div??

    var thumbcap = $j(this).parent('a').closest(p).html(); ??? This selects always the firs div p content.

    Thank you in advance...
     
    WillPooleDesigns, Jun 18, 2014 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    $(this).parents('div').find('p').html(); should work - however, in the code you provided there's no "outer" div - there are consequtive divs - ie, first one div, containing an A, an IMG and a P-tag, then another DIV containing the same.
     
    PoPSiCLe, Jun 20, 2014 IP