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 / link also but i didn't find my answer.
is it possible to get status like true/false or something like this?
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./toggle/ link also but i didn't find my answer.
is it possible to get status like true/false or something like this?
Share Improve this question asked Sep 5, 2013 at 6:04 404 Not Found404 Not Found 1,2232 gold badges22 silver badges31 bronze badges 3-
3
Why don't you check if it has the class?
var toggle = $(this).hasClass('opa')
– elclanrs Commented Sep 5, 2013 at 6:07 - can you give some bit more information so i can try to implement you suggestion.. – 404 Not Found Commented Sep 5, 2013 at 6:09
- 1 Check out this link if it helps stackoverflow./questions/2388664/… – MarsOne Commented Sep 5, 2013 at 6:10
2 Answers
Reset to default 6Try this,
$(document).ready(function(){
var neck='';
var chest='';
$("#neck,#chest").click(function(){
if($(this).toggleClass('opa').hasClass('opa')){
neck = "neck";
}else{
neck = "";
}
});
});
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./toggle/#toggle-showOrHide