Saturday, 31 March 2018

jquery - Can I use CSS3 Selectors to select based on a child element?



I need to select a

element that has a nested with a specific class.



The is not always a child of the

and may instead be a grandchild. For example:



some textlink




I need to select the

element if it has an with the class f5 anywhere inside.



Answer



this isn't possible with a css selector (theres nothing like a parent-selector).



maybe you can work around this with javascript - in jquery, for example, you should get your paragraphs with $('p:has(a.f5)') (and then you're free to .addClass() or set .css() on this elements directly).



EDIT::
you might also want to take a look at this other questions on SO (and next time: search before you ask):




No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...