3

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

Community
  • 1
  • 1
user906080
  • 125
  • 1
  • 11

2 Answers2

3

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;
Josh
  • 11,980
  • 9
  • 70
  • 116
3

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;
}
Kevin Le - Khnle
  • 9,509
  • 8
  • 46
  • 76