Пример:
Добавить класс "test" ко всем элементам div, которые имеют вложенный параграф.
"HTML"
<div>Hello in a paragraph
</div> <div>Hello again! (with no paragraph)</div>
"CSS"
.test{ border: 3px inset red; }"Живой пример jQuery"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link href="http://slyweb.ru/css/jqueryiframe.css"
rel="stylesheet" type="text/css"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("div:has(p)").addClass("test");
});
</script>
</head>
<body class="iframe">
<div>Hello in a paragraph
</div>
<div>Hello again! (with no paragraph)</div>
</body>
</html>
<style>
.test{ border: 3px inset red; }
</style>