jQuery Selector: Select elements where attribute attr=value

A way to use jQuery selectors is to select HTML elements by their attribute values.

Here we select a clear buton and when it is clicked, a message is displayed.

<!DOCTYPE html>
<html>
<head lang='en'>
    <meta charset='UTF-8'>
    <title>Codecrawl.com-Form</title>
    <script src='//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js'></script>
    <script>
        $(function () {
            $("input[value='Clear']").click(function () {
                $('.message').show();
            });
        });
    </script>
</head>
<body>
<br>
Name: <input type='text' name='name'>
<br>
Phone: <input type='text' name='phone'>
<br>

Comments:
<br>
<textarea name='comment' rows='3'></textarea>
<br>
<input type='submit' value='Send'>
<input type='reset' value='Clear'>

<p class='message' style='display: none; color: grey'>Inputs Cleared</p>

</body>
</html>

Series Navigation<< jQuery Selectors: Appending a li to an ul element
jQuery Selectors: Select all elements that match a substring >>