[attribute~=value] selector selects elements whose attribute contains a word. - Javascript jQuery Selector

Javascript examples for jQuery Selector:attribute contains a word

Description

The [attribute~=value] selector selects elements whose attribute contains a word.

Syntax

Parameter Description
attribute Required. Specifies the attribute to find
value Required. Specifies the string value

The following code shows how to select all <input> elements with a name attribute that contains the word "test":

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("input[name~='test']").css("background-color", "red");});
</script>//from w  w w  . j av a2s  .  c om
</head>
<body>

<input name="test" type="text" value="test">
<div name="test">test</div>
<input name="tests" type="text" value="tests">
<input name="test case" type="text" value="test case">

</body>
</html>

Related Tutorials