jQuery Selectors: Attribute attr begins with a value

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

Here we use jQuery selectors to select an <img> elements whose src attribute starts with http.

The image is sized to a height of 200px through a jQuery selector.

The syntax is $(‘[attr^=value]’).

<!DOCTYPE html>
<html>
<head lang='en'>
    <meta charset='UTF-8'>
    <title>Codecrawl.com-Image</title>
    <script src='//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js'></script>
    <script>
        $(function () {
            $("img[src^='http']").css('height', '200px');
        });
    </script>
</head>
<body>

<h4>Ushuaia</h4>

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

<img src='http://codecrawl.com/code/images/ushuaia.jpg'>

</body>
</html>

 

Series Navigation<< jQuery Selectors: Select all elements that match a substring
jQuery Selectors: Using meta or special characters >>

Leave a comment

Leave a Reply