Reputation: 1223
i am newbie in JQuery.
i want to get status of toggle() like it's true or false?
here i want to set variable when toggle gets clicked as true, and when its gets false i want to reset that variable value again.
$(document).ready(function(){
var neck='';
var chest='';
$("#neck,#chest").click(function(){
$(this).toggleClass('opa');
})
})
here in class opa i am just setting opacity level. if it's true then opacity 1 and if it's false then opacity 0.
This code is working fine its toggling class (adding & Removing).
but i want to set neck value as neck="neck" when it's true (clicked first time #neck) or set neck=""; when it's false (clicked second time #neck).
i referred http://api.jquery.com/toggle/ link also but i didn't find my answer.
is it possible to get status like true/false or something like this?
Upvotes: 3
Views: 4491
Reputation: 2763
Try this,
$(document).ready(function(){
var neck='';
var chest='';
$("#neck,#chest").click(function(){
if($(this).toggleClass('opa').hasClass('opa')){
neck = "neck";
}else{
neck = "";
}
});
});
Upvotes: 6
Reputation: 285
You should read. This is the way to set boolean values in toggle. Where you can simple pass your neck variable with desired value.
http://api.jquery.com/toggle/#toggle-showOrHide
Upvotes: 0