Пример:
Проверить присутсвует ли обозначенный класс у элемента, если класс присутствует, выполнить дейтсвие.
"jQuery"
$("div").click(function(){
if ( $(this).hasClass("protected") )
$(this).animate({ left: -10 }, 75)
.animate({ left: 10 }, 75)
.animate({ left: -10 }, 75)
.animate({ left: 10 }, 75)
.animate({ left: 0 }, 75);
});
"HTML"
<span></span><div class="protected"></div> <span></span><div></div> <span></span><div></div> <span></span><div class="protected"></div>
"CSS"
div { width: 80px; height: 80px; background: #abc;
position: relative; border: 2px solid black;
margin: 20px 0px; float: left; left:0 }
div.protected { border-color: red; }
span { display:block; float:left; width:20px;
height:20px; }
"Живой пример 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").click(function(){
if ( $(this).hasClass("protected") )
$(this).animate({ left: -10 }, 75)
.animate({ left: 10 }, 75)
.animate({ left: -10 }, 75)
.animate({ left: 10 }, 75)
.animate({ left: 0 }, 75);
});
});
</script>
</head>
<body class="iframe">
<span></span><div class="protected"></div>
<span></span><div></div>
<span></span><div></div>
<span></span><div class="protected"></div>
</body>
</html>
<style>
div { width: 80px; height: 80px; background: #abc;
position: relative; border: 2px solid black;
margin: 20px 0px; float: left; left:0 }
div.protected { border-color: red; }
span { display:block; float:left; width:20px;
height:20px; }
</style>