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
  • 2
  • 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
  • 12,448
  • 10
  • 74
  • 118
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
  • 10,579
  • 11
  • 54
  • 80