How do you add a class to an anchor if its parent has the class xyz
I got so far…
if($("a").parents(".xyz").length > 0) {
addClass(".xyz")
};
obviously this isn’t working otherwise I wouldn’t be here asking 🙂
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Simply do
This will add the class
xyzto all elementsahaving a parent of classxyx.To be less ambiguous : if you want to add the class
xyzto all elementsahaving a parent of classabc, useIf you want to be sure that there is a direct parent child relation, use