jQuery Selectors: Attribute attr not equal to a value

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

We could have $(‘[attr=value]’), we could also negate the value using $(‘[attr!=value]’).

So only clicking on Clear button below will display a message.

<!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!='Send']").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: Using meta or special characters
jQuery Selectors: Select elements that have attribute $(‘[attr]‘) >>

Leave a comment

Leave a Reply