Here is my function atm:
$(document).ready(function() { $("#knd").click(function() { $("#wars").animate({ opacity:'1' }); }); });
It works great but I want to add the option to remove the box with another click, figured I'd do it with an if statement but I'm not 100% on the syntax in Jquery. I want something along the lines of:
if(#wars is visible) { $("#wars").animate({ opacity:'0' });
How would I write the if statement for this?
SOLUTION:
$(document).ready(function() { $("#knd").click(function() { if($("#wars").css('opacity') === '0') { $("#wars").animate({ opacity:'1' }); //end of animate } else { $("#wars").animate({ opacity:'0' }); //end of animate } }); //end of KND click function }); //end of doc ready function
I had to change the visibility and set it to opacity instead, then it worked like a charm with the if statement.
The noConflict() method releases jQuery's control of the $ variable. This method can also be used to specify a new custom name for the jQuery variable. Tip: This method is useful when other JavaScript libraries use the $ for their functions.
1) Using jQuery If you are someone strongly committed to using the jQuery library, you can use the . inArray( ) method. If the function finds the value, it returns the index position of the value and -1 if it doesn't.
=== This is the strict equal operator and only returns a Boolean true if both the operands are equal and of the same type.
You can use .is() along with :visible selector:
if($('#knd').is(':visible')) { $("#wars").animate({ opacity:'0' }); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With