MeltingDog MeltingDog - 2 years ago 68
jQuery Question

Is there a better way to select multiple elements that have the same parent elements?

Is there a way I can simplify this selector, seeing as the parent elements are the same?

$(".card .card-title .fa-star-o, .card .card-title .fa-star")

eg something like:

$(".card .card-title (.fa-star-o, .fa-star)")

(above doesnt work, obviously)

The comma way does work of course, but I'm just wanting to know if there's a better, cleaner way.

Answer Source

Here it's

$(".card .card-title").find(".fa-star-o, .fa-star")
                      .css({"color": "red", "border": "2px solid red"});
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download