<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<style type="text/css">
div{ float:left; border:solid 1px #ccc; width:65px; height:65px; }
span{ float:left; border:solid 1px #ccc; width:45px; height:45px; background-color:#eee;}
.classadd{ background-color:Red;}
</style>
<script src="jquery-1.9.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('#btn').click(function () {
//为div元素中所有文本包括A的元素添加样式,包括嵌套元素
$('div:contains(A)').addClass('classadd');
//为div元素中所有不包括子元素或者文本的元素添加样式
//$('div:empty').addClass('classadd');
//为div元素中所有包含span元素的元素设置样式,不包含span元素
//$('div:has(span)').addClass('classadd');
//为所有包含子元素或者文本的元素设置样式
//$('div:parent').addClass('classadd');
})
})
</script>
</head>
<body>
<form id="form1" >
<div>ABCD</div>
<div><span></span></div>
<div>EACH</div>
<div></div>
<div><div>CAD</div></div>
<div><span></span></div>
<input type="button" id="btn" value="点我" />
</form>
</body>
</html>