jQuery has() by element and attribute

Description

jQuery has() by element and attribute

View in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("p span").has("a[href]").css("background-color", "yellow");
});/*from  www.  j  a v  a 2s  .co  m*/
</script>
</head>
<body>

<h1>Welcome to My Homepage</h1>

<p>My <span>name</span> is CSS.</p>
<p>this is a test from <span><a href="https://www.java2s.com">java2s.com</a></span>.</p>
<p>This <span>is</span> another test.</p>

</body>
</html>



PreviousNext

Related