[attribute=value] selector selects elements for the specified attribute and value. - Javascript jQuery Selector

Javascript examples for jQuery Selector:attribute value

Description

The [attribute=value] selector selects elements for the specified attribute and value.

Syntax

Parameter Description
attribute Required. attribute to find
value Required. value to match

The following code shows how to select every element containing an id attribute with the value "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(){
    $("[id=test]").css("background-color", "yellow");
});/*from  w ww .  j  a  v  a 2 s  .c o m*/
</script>
</head>
<body>

<h1>Welcome to My Homepage</h1>

<p class="intro">This is a test.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>

Who is your favourite:
<ul id="test">
  <li>A</li>
  <li>B</li>
  <li>C</li>
</ul>

</body>
</html>

Related Tutorials