jQuery - exp mit is() _02
is function()
by juErik
HTML
<ul>
<li><strong>list</strong> item 1 - one strong tag</li>
<li><strong>list</strong> item <strong>2</strong> -
two <span>strong tags</span></li>
<li>list item 3</li>
<li>list item 4</li>
<li>list item 5</li>
</ul>
JavaScript
/* hier wird der li mit den zwei '<strong>'s anders behandelt*/
$("li").hover(function() {
var $li = $(this);
isWithTwo = $li.is(function() {
return $('strong', this).length === 2;
});
if ( isWithTwo ) {
$li.css("background-color", "green");
} else {
$li.css("background-color", "red");
}
});
// remove background
$("li").mouseout(function(){
$(this).css("background-color", "transparent");
});