jQuery Selectors: Select all elements that match a substring

This entry is part 8 of 33 in the series jQuery Selectors

As in CSS3 selectors, we can select elements that match a substring in a class.

For example, the 2 classes below both contain the substring Line.

Its syntax is E[attr*=value].

<!DOCTYPE html>
    <script src='//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js'></script>
        $(function () {
            $('p[class*=Line]').css('color', 'blue');

<p>Southernmost city in the world.</p>

<p class='firstLine'>The city centered around a prison built by the Argentine government.</p>

<p class='secondLine'>They also built a railway to the settlement, now a tourist attraction known as the End of the World Train, the
    southernmost railway in the world.</p>

<a href='http://en.wikipedia.org/wiki/Ushuaia'>Visit us here.</a>


Series Navigation<< jQuery Selector: Select elements where attribute attr=value
jQuery Selectors: Attribute attr begins with a value >>

Leave a comment

Leave a Reply