44 Views

21st August 2020

Jquery Selector Attribute

What is jQuery [attribute=value] Selector?

Answers

21st August 2020

Answered by ravi sankar

The [attribute = value] selector, selects every element with the particular attribute and value.

Syntax:

$(“[attribute=value]”)

Example:

<!DOCTYPE html>

<html>

<head>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

<script>

$(document).ready(function(){

  $("[id=choose]").css("background-color", "red");

});

</script>

</head>

<body>

<h1>Welcome</h1>

<p class="intro">My name is Schinchan.</p>

<p>I live in Kasukabe.</p>

<p>My best friend is Masaw.</p>

Who is your favourite:

<ul id="choose">

  <li>Hiroshi</li>

  <li>Actionkamen</li>

  <li>Mitsi</li>

</ul>

</body>

</html>

 

Write your answer
Request a Free Demo

Meet the Expert Who Can Kickstart Your Career