Click here to Skip to main content
15,891,423 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have this code:

VB
$("#Panel ul li a").find("[value='art6']").parent().css("styles here");


i want to access the Li , father of A , and manipulate it!
but it does not work how can i do that?

plz help!
Posted
Updated 25-Sep-13 3:51am
v3

In jQuery, the find() method is to
"Get the descendants of each element in the current set of matched elements, filtered by a selector, jQuery object, or element."

So the problem is that your first selector goes all the way down to the anchors themselves, then your find() is looking for a descendant of an anchor.

Change to this and it will work:
$("#Panel ul li").find("a[value='art6']").parent().css("styles here");
 
Share this answer
 
v3
In your example code you are not asking for the parent of a.

$("#Panel ul li a").find("[value='art6']") will look for an element inside a matching [value='art6'].

Find returns the element you were looking for (or 0 length jQuery wrapper if it can't find it) and as such when using .parent() on the result of .find() you are asking for the parent of [value='art6'] instead, which is not a.

Not knowing how deep your element [value='art6'] is inside a your best bet is to use:
JavaScript
$("#Panel ul li a").find("[value='art6']").closest('li').css("styles here");


However, if you wanted to look for an a element which itself has a value of art6 then your selector is wrong to begin with and should be this:
JavaScript
$("#Panel ul li a[value='art6']").parent().css("styles here");


In the above scenario the li can be omitted as the direct parent to your selector is the li already.

As you have not posted your actual HTML markup it is not possible to know if your selector is wrong or your usage of .parent() but hopefully one of the examples above helps you in solving your issue.
 
Share this answer
 
v2
Comments
Brian A Stephens 25-Sep-13 12:36pm    
After I posted my answer and saw yours, I realized that he must be looking for an element with value="art6" INSIDE an anchor because "value" is not a valid attribute of an anchor tag.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900