Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Syntax Meaning [duplicate]

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

like image 827
user906080 Avatar asked Mar 15 '26 11:03

user906080


2 Answers

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;
like image 73
Josh Avatar answered Mar 17 '26 23:03

Josh


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;
}
like image 28
Kevin Le - Khnle Avatar answered Mar 18 '26 01:03

Kevin Le - Khnle



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!