Switch with is method
Description
The following code shows how to switch with .is() method.
Example
<html>
<head>
<script
src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {<!--from ww w . j a v a 2 s.c om-->
$("div").one('click', function() {
if ($(this).is(":first-child")) {
$("p").text(":first-child");
} else if ($(this).is(".blue,.red")) {
$("p").text("It's a blue or red div.");
} else if ($(this).is(":contains('java2s.com')")) {
$("p").text("It's java2s.com!");
} else {
$("p").html("It's nothing <em>special</em>.");
}
});
});
</script>
<style>
div.middle {
color: red;
}
</style>
</head>
<body>
<body>
<div>java2s.com</div>
<div class="blue">jav a2s.com</div>
<div class="red">java2s.com</div>
<div>
<span>java2s.com</span>java 2s.com
</div>
<div class="blue">java2s.co m</div>
<p>java2s.com</p>
</body>
</html>