jQuery [attribute~=value] Selector Last Updated : 11 Jul, 2025 Suggest changes Share Like Article Like Report jQuery [attribute~=value] Selector Select all elements with a name attribute that contains the specific string. Syntax: $("[attribute~='string']")Parameter: attribute: Specifies which attribute is used to find.string: Specifies the string value to find.Example 1: In this example, we will select all the elements which have name attribute by using jQuery [attribute~=value] Selector. HTML <!DOCTYPE html> <html> <head> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"> </script> <script> $(document).ready(function () { $("input[name~='GFG']").css("background-color", "LIGHTGREEN"); }); </script> </head> <body> <input name="GFG" type="text" value="GEEKSFORGEEKS"> <input name="2" type="text" value="SITE1"> <input name="3" type="text" value="SITE2"> <input name="GFG" type="text" value="GEEKSFORGEEKS"> <input name="GFG" type="text" value="GEEKSFORGEEKS"> <input name="4" type="text" value="SITE4"> <input name="GFG" type="text" value="GEEKSFORGEEKS"> </body> </html> 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 <!DOCTYPE html> <html> <head> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"> </script> <script> $(document).ready(function () { $("button").click(function () { $("input[name~='GFG']").css("color", "GREEN"); }); }); </script> </head> <body> <input name="GFG" type="text" value="GEEKSFORGEEKS"> <input name="1" type="text" value="SITE1"> <input name="GFG" type="text" value="GEEKSFORGEEKS"> <input name="2" type="text" value="SITE2"> <input name="3" type="text" value="SITE3"> <input name="GFG" type="text" value="GEEKSFORGEEKS"> <input name="4" type="text" value="SITE4"> <input name="GFG" type="text" value="GEEKSFORGEEKS"> <br><br> <button>Change color</button> </body> </html> Output: A AkshayGulati Follow Article Tags : Web Technologies JQuery jQuery-Selectors Explore jQuery Tutorial 7 min read Getting Started with jQuery 4 min read jQuery Introduction 7 min read jQuery Syntax 2 min read jQuery CDN 4 min read jQuery SelectorsJQuery Selectors 5 min read jQuery * Selector 1 min read jQuery #id Selector 1 min read jQuery .class Selector 1 min read jQuery EventsjQuery Events 4 min read jQuery bind() Method 2 min read jQuery blur() Method 1 min read jQuery change() Method 2 min read jQuery EffectsjQuery animate() Method 2 min read jQuery clearQueue() Method 2 min read jQuery delay() Method 2 min read jQuery HTML/CSSjQuery addClass() Method 2 min read jQuery after() Method 1 min read jQuery append() Method 2 min read jQuery TraversingjQuery | Traversing 4 min read jQuery add() method 1 min read jQuery addBack() Method 2 min read My Profile ${profileImgHtml} My Profile Edit Profile My Courses Join Community Transactions Logout Like