Possible Duplicate:
How do you read this JavaScript code? (var1 ? var2:var3)
JS How to use the ?: (ternary) operator
I was looking at a website's code and found this:
$.body = $('body');
$.scroll = ($.browser.mozilla || $.browser.msie) ? $('html') : $.body;
What is the second line saying? Looks like some sort of if statement
Thanks
If the browser is mozilla, or if the browser is msie, then select the html dom object, else, select the body.
var a = CONDITION ? IF_TRUE : IF_FALSE;
It could have also been written as (but most people would prefer the style that you posted):
if ($.browser.mozilla || $.browser.msie) {
$.scroll = $('html');
} else {
$.scroll = $.body;
}
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