jQuery Selector: Select elements where attribute attr=value

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

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>
<head lang='en'>
    <meta charset='UTF-8'>
    <script src='//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js'></script>
        $(function () {
            $("input[value='Clear']").click(function () {
Name: <input type='text' name='name'>
Phone: <input type='text' name='phone'>

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

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


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