Open In App

How to find all inputs that don’t have color name and appends text to the span next to it using jQuery ?

Given some input elements and the task is to find all inputs that don’t have the name = “color” and append text to the span next to it using jQuery. In simple words, we have to find all the input with the name != “color” and then we have to append some text next to the span element.

Used Method:



Approach:

Example: In this example, we will use the above approach.






<!DOCTYPE html>
<html>
 
<head>
    <script src="https://code.jquery.com/jquery-git.js">
    </script>
 
    <style type="text/css">
        body {
            text-align: center;
            font-size: 20px;
        }
 
        button {
            background-color: #4CAF50;
            /* Green */
            border: none;
            color: white;
            padding: 15px 32px;
            text-align: center;
            text-decoration: none;
            display: inline-block;
            font-size: 16px;
        }
    </style>
</head>
 
<body>
    <h1 style="color:green;">GeeksForGeeks</h1>
    <h2>choose colors name from the below list.</h2>
    <div>
        <input type="checkbox" name="color" value="Red">
        <span>Green</span>
    </div>
    <div>
        <input type="checkbox" name="animal" value="good">
        <span>Tiger</span>
    </div>
    <div>
        <input type="checkbox" name="birds" value="fly">
        <span>Birds</span>
    </div>
    <br>
    <button id="button1">Click to see the effect</button>
 
    <script>
        $('#button1').click(function () {
            $("input[name!='color']").next()
                .append("<b>: This is not a color</b>");
        });
    </script>
</body>
 
</html>

Output:

 


Article Tags :