jQuery .delegate() on multiple elements
When using the .delegate
can I choose multiple elements or should I have to use .delegate
for every element that I need to work with? (function will be the same for all elements)
e.g.
$('#div').delegate开发者_开发技巧('a', 'click' (function(){ // This is ok
.delegate('a, element_2, element_3', 'click' (function(){ // IS THIS OK??
That is fine since 'a, element_2, element_3'
is a valid selector, which is the first argument of .delegate().
BUT, your arguments are not separated by commas properly, it should be:
$('#div').delegate('a, element_2, element_3', 'click', function(){
//function go here
});
That second method appears to be okay as it a, element_1, element_2
returns a set of elements that will have the .delegate()
function applied.
Yes it is OK, the documentation states
.delegate( selector, events )
Selector being any valid jQuery selector. even your first call may return more than one element.
精彩评论