javascript - What does brackets and parentheses after jquery selector mean? -


i ran line of code , can't figure out means:

$("#theappcontainer")[s > u ? "addclass" : "removeclass"]("something"); 

i understand first part selecting element called theappcontainer , second part evaluates "addclass" if s > u, can't figure out line of code overall.

the bracket syntax gets value of property name, , parentheses call function value of property. it’s equivalent to:

var container = $('#theappcontainer');  if(s > u) {     container.addclass('something'); } else {     container.removeclass('something'); } 

also, please never write code that. =)

also also, toggleclass takes second switch argument can use instead:

$('#theappcontainer').toggleclass('something', s > u); 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -