Link to home
Start Free TrialLog in
Avatar of coolispaul
coolispaulFlag for United States of America

asked on

Selecting an element with jquery

Hi

I have an html  page with attached code in. When i click the anchor link (id = "click6") i want to select the div that is directly previous to it . (the one that has display none)

How can i do that with jquery?

Thanks
<div style="width:590px; float:right; margin-top:32px;">
    <p>content...</p>
    
    <div style="display: none">
     <p>Content<p>
    </div>
    <p><a id="click6" name="click">EXPAND BIO</a>.</p>

Open in new window

Avatar of Gurvinder Pal Singh
Gurvinder Pal Singh
Flag of India image

following code will highlight that div when the link is clicked

$("a#click6").bind("click", function(){

 $(this).prev("div").css("border", "2px solid red")
});
ASKER CERTIFIED SOLUTION
Avatar of Eyal
Eyal
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of coolispaul

ASKER

great yes it works with parent()

Why doesnt  $(this).prev("div") work? thats actually what i tried..

Cheers
because anchor is inside the <p> and is not at the same level as div
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
oh ok i thought .prev(div) just looked for the previous "div" element in the HTML regardless of being sibling or not.

Ok thanks