Posted on 16th September 2024|24 views
What is jQuery [attribute=value] Selector?
Posted on 16th September 2024| views
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>