Is the first .on function more efficient than second one ?
$( "div.container" ).on( "click", "p", function(){
});
$( "body" ).on( "click", "p", function(){
});
Regards
Is the first .on function more efficient than second one ?
$( "div.container" ).on( "click", "p", function(){
});
$( "body" ).on( "click", "p", function(){
});
Regards
The narrower the first selector is, the better the performance is.
But the first example won't work I guess, because you are monitoring all the <p>
s container in <p>
s having container
class, and a <p>
cannot contain another <p>
, due to being a phrasing content.
From the jQuery documentation itself about jQuery: .on():