i'm curious of following (in theory) better in terms of dom efficiency. realize both snippets written more concisely i'm trying find out when , use , if/else vs. making 2 different jquery calls.
snippet 1
$('.ele').click(function() { if ($(this).hasclass('force')) { //use } else { //hide } }); snippet 2
$('.ele.force').click(function() { //use }); $('.ele.ring').click(function() { //hide });
its avoid conditional statements , use functions. if dont know state @ time of event trigger end using conditions in function.
but here know if element(.ele) has class .force behavior //use it or else //hide. better have 2 separate event handlers.
note: safe use .on()/.live() kind of binding because element might change state.
Comments
Post a Comment