[ jquery 选择器 :parent ] 此方法选取匹配含有子元素或者文本的元素

匹配含有子元素或者文本的元素,与:empty(查找所有不包含子元素或者文本的空元素)作用相反

实例:

<!DOCTYPE html>
<html>
<head>
<meta charset=' utf-8'>
<meta name='author' content='http://www.52jb.net/' />
<title>Inset you title</title>
<style type='text/css'>
    *{margin:0;padding:0;}
    .active{color:#F30;font:900 15px/1.2em "Courier New";}
</style>
<script type='text/javascript' src='./js/jquery-1.12.1.min.js'></script>
<script type='text/javascript'> 
    $(function(){ 
      $('button').click(function(){ 
        $('div:parent').toggleClass('active');
      });
    });
</script>
</head>
<body>
    <div></div>
    <div><span></span></div>
    <div>span</div>
    <div></div>
    <button type='button'>button</button>
</body>
</html>
原文地址:https://www.cnblogs.com/mysearchblog/p/5606232.html