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>
<head lang='en'>
    <meta charset='UTF-8'>
    <script src='//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js'></script>
        $(function () {
            $("input[value!='Send']").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: Using meta or special characters
jQuery Selectors: Select elements that have attribute $(‘[attr]‘) >>

Leave a comment

Leave a Reply