hey all,
what does it mean where there are two id's in the jquery selector using the .live method?
for example:
$('#mybtn', '#mydiv').live('click', function...
thanks, rodchar
hey all,
what does it mean where there are two id's in the jquery selector using the .live method?
for example:
$('#mybtn', '#mydiv').live('click', function...
thanks, rodchar
This is using context. It is considered a bad practice to pass in a string as the context, but it works. It's equivalent to this:
$('#mydiv').find('#mybtn').live('click', function...
It means search for an element with id="mybtn"
within an element with id="mydiv"
Seems rather pointless to do such a thing when you are looking by ID. Because ID is always supposed to be unique.
$('#mybtn', '#mydiv')
would pass #mydiv as the context parameter to the jQuery $ function (jQuery core documentation)
If you meant
$('#mybtn,#mydiv')
this would bind the live event handler to both matched elements (elements with ID mybtn and mydiv). The comma is standard CSS syntax for matching more than one selector. The $ function would return a jQuery object with length=2 (assuming that one instance of both mybtn and mydiv exist on the page). The 'live' function will bind live events to both elements.