Friday, 15 June 2012

target all parents(".class") of a specific class jquery -


I am having trouble targeting all parents with a specific class set.

If I click on George Michael, then I have to say, "Michael" and "George SR" with & lt; P & gt; want to change the color of the tag.

Below the Dummy HTML and Jacqueline which has failed.

  & lt; Ul & gt; & Lt; Li & gt; & Lt; Div class = "leaf" & gt; & Lt; P & gt; George S & lt; / P & gt; & Lt; / Div & gt; & Lt; Ul & gt; & Lt; Li & gt; & Lt; Div class = "leaf" & gt; & Lt; P & gt; Michael & lt; / P & gt; & Lt; / Div & gt; & Lt; Ul & gt; & Lt; Li & gt; & Lt; Div class = "leaf" & gt; & Lt; P & gt; George Michael & lt; / P & gt; & Lt; / Div & gt; & Lt; / Li & gt; & Lt; / Ul & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; Div class = "leaf" & gt; & Lt; P & gt; Gubbs & lt; / P & gt; & Lt; / Div & gt; & Lt; Ul & gt; & Lt; Li & gt; & Lt; Div class = "leaf" & gt; & Lt; P & gt; Steve Halt & lt; / P & gt; & Lt; / Div & gt; & Lt; / Li & gt; & Lt; / Ul & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; Div class = "leaf" & gt; & Lt; P & gt; Lindsey & lt; / P & gt; & Lt; / Div & gt; & Lt; Ul & gt; & Lt; Li & gt; & Lt; Div class = "leaf" & gt; & Lt; P & gt; Maeby & lt; / P & gt; & Lt; / Div & gt; & Lt; / Li & gt; & Lt; / Ul & gt; & Lt; / Li & gt; & Lt; / Ul & gt;   

I tried to:

  $ (document) .on ("click", '.leaf', Function () {$ (this) .Parents (". Leaf"). Children ('P'). CSS ('color', 'red');});   

Edit the request: Also, someone can tell why the above jquery does not work?

Please help :)

For your use:

In this way:

  $ (document) .on ("click ('& gt; .leaf & gt; p'). 'Css' ('color', '' '', '.', 'Red');});   



No comments:

Post a Comment