首页javascriptrelationjQuery Selector - 如何按照名称在父元素中定位元素

jQuery Selector - 如何按照名称在父元素中定位元素

我们想知道如何按照名称在父元素中定位元素。

<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.8.3.js'></script>
<style type='text/css'>
#id2 .mycolor {
  color: white;
  background-color: red;
}

#id3:active {
  color: red;
  background-color: white;
}
</style>
<script type='text/javascript'>
$(function(){
    $('#id2').find('span').addClass('mycolor');
});
</script>
</head>
<body>
  <div id="id2">
    <span>Demo</span>
  </div>
</body>
</html>