Add a red color to the <span> element that is the descendant of <ul> with the find() method. - Javascript jQuery

Javascript examples for jQuery:Tag Traversing

Description

Add a red color to the <span> element that is the descendant of <ul> with the find() method.

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
.ancestors * {//from w w  w. ja  v  a2 s . c  o  m
    display: block;
    border: 2px solid lightgrey;
    color: blue;
    padding: 5px;
    margin: 15px;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("ul").find("span").css({"color": "red"});
});
</script>
</head>
<body>

<div class="ancestors">
  <div style="width:500px;">div
    <ul>ul
      <li>li
        <span>span</span>
      </li>
    </ul>
  </div>
</div>

</body>
</html>

Related Tutorials