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
Post a Comment