jQuery [attribute~=value] Selector (original) (raw)

Last Updated : 11 Jul, 2025

jQuery [attribute~=value] Selector Select all elements with a name attribute that contains the specific string.

Syntax:

$("[attribute~='string']")

Parameter:

Example 1: In this example, we will select all the elements which have name attribute by using jQuery [attribute~=value] Selector.

HTML `

<script>
    $(document).ready(function () {
        $("input[name~='GFG']").css("background-color",
            "LIGHTGREEN");
    });
</script>

`

Output:

Example 2: In this example, we will change the color of all the elements which have name attribute with the help of click function.

HTML `

<script>
    $(document).ready(function () {
        $("button").click(function () {
            $("input[name~='GFG']").css("color",
                                        "GREEN");
        });
    });
</script>


Change color

`

Output: