Reputation: 32331
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
var value = $("p").removeClass("intro");
});
});
</script>
<style>
.intro
{
font-size:120%;
color:red;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p class="intro">This is a paragraph.</p>
<p class="intro">This is another paragraph.</p>
<button>Remove the "intro" class from all p elements</button>
</body>
</html>
Hi ,
This is my program for removing some class
My question is that how can i know if the removeclass operation is success or failure ??
$("p").removeClass("intro");
can have any return type set for this ??
Upvotes: 0
Views: 150
Reputation: 7020
<script>
$(document).ready(function(){
$("button").click(function(){
$("p").removeClass("intro");
if ($("p").hasClass("intro"))
{
alert("class not removed !");
}
});
});
</script>
Upvotes: 1
Reputation: 26013
You can verify whether the node still has the class after you've performed .removeClass()
on it with the .hasClass()
function:
if ($('p').hasClass('intro')) {
...
}
Upvotes: 1
Reputation: 82241
You can use .hasClass()
to verify that:
$("p").hasClass("intro")
Upvotes: 6