jquery question

Soldato
Joined
18 Oct 2002
Posts
4,925
Location
Yorkshire
using jquery i'm trying to traverse some dom objects, then hide one. heres some example html

Code:
HideShowElement(elementID)
{
   // here I'm changing the 'elementID''s object supplied to this 
  // so that the element is now showing. I can do this fine

  // Here I need to use the element above and traverse up to get its parent
 // then get the paragraph child that has the class SummaryTextHolder"   and  hode this element.

 // I was trying the following but it doesn't seem to work.
  $("#"+elementID).Parent().("p.SummaryTextHolder").Hide();

 
}

<div>
   <div id="g10d3" display="hidden">
       <p>blar blar some more text</p>
   </div>
   <p class="SummaryTextHolder">This is the paragraph I want to hide</p>
    <img src="test.jpg" alt="test" onClick="HideShowElement("g10d3")"/>
</div>

If I break the above down to $("#"+elementID).Parent() it gets the parent ok but i can't seem to find a way to use that to get the p.SummaryTextHolder element.
 
Ignore / Delete etc kind of answered my own question when writing this.

I should have used
$("#"+elementID).Parent().children("p.SummaryTextHolder").Hide();
 
Code:
var parent = $("#" + elementID).parent();
$("p.SummaryTextHolder", parent).hide();

The second parameter to $("expression") is called "context", and specifies the root element under which jQuery will match expression.
 
Unfortunately i'm being forced to do it like that as the guy in charge seems to think that it could become too confusing if the events aren't clearly marked on the elements.

He seems to think that people will see an event happening and won't know whats being called as they can't read the html and clearly see the onClick. :rolleyes:
 
Back
Top Bottom