From the course: jQuery Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Attribute filters

Attribute filters - jQuery Tutorial

From the course: jQuery Essential Training

Start my 1-month free trial

Attribute filters

- You can get pretty far using the basic jQuery filters but you'll run into scenarios where you need a little bit more power. jQuery provides some more advanced filters which we'll take a look at now. So in your code editor, open up the AttrFilters_start file. The attribute filters in jQuery let you perform various tests to see if attributes are present and optionally contain certain values. In this first example, I'll write a jQuery selector that's looking for paragraph tags. And for attribute filters, we put the attributes inside square brackets. Let me go ahead and write the code for that. I'm gonna write p, and then class inside these square brackets and then I'll use my CSS function to highlight it. In this case, my selector looks for paragraph tags and using this syntax, the name of the attribute inside these square brackets, it's looking for paragraph tags that have a class attribute and in this case, we don't care what the value is. We're just testing to see if it's there. If…

Contents