Chris W. Parker wrote:
On Thursday, June 21, 2007 9:48 AM Klaus Hartl said:

$(document).ready(function() {
 $("[EMAIL PROTECTED]'section']").click(function(){
  $(this)[this.checked ? 'addClass' : 'removeClass']('checked'); });
});

What kind of syntax is that third line? (I don't mean the ternary
operator.)

JavaScript supports the array-element notation for every object, allowing you to access properties (or methods, which are nothing more then properties) based on a variable at runtime. Its the same as this:

if(this.checked) {
 $(this).addClass('checked');
} else {
 $(this.removeClass('checked');
}

Or, using the ternary operator:

this.checked ? $(this).addClass('checked') : $(this).removeClass('checked')

--
Jörn Zaefferer

http://bassistance.de

Reply via email to