[attribute] Selector - Javascript jQuery Selector

Javascript examples for jQuery Selector:attribute

Description

The [attribute] selector selects elements with the attribute.

Syntax

Parameter Description
attribute Required. attribute to find

The following code shows how to select every element with an id attribute:

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", "red");
});// ww w.j av a 2  s  .  c om
</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