Reputation: 7288
Do you know why using removeClass
after hasClass
give me Uncaught TypeError: undefined is not a function
?
In code below, the alert won't be executed since the code above it produce an error..
$("input[type='button']").hasClass("scroll").removeClass("inactive");
alert("success");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Can anybody provide other way to achieve my goal?
Upvotes: 3
Views: 1404
Reputation: 3247
jQuery hasClass
returns boolean, which have no removeClass
method. In your case it's much better to put class selector inside $
call
$("input[type='button'].scroll").removeClass("inactive");
Upvotes: 6
Reputation: 15393
.hasClass
check with if condition it returns boolean
if($("input[type='button']").hasClass("scroll")){
$("input[type='button']").removeClass("inactive")
}
Upvotes: 5