javascript - How do I gather multiple jQuery objects into one jQuery object? -
say have these variables:
var container = $("div#my-awesome-section"); var foo_input = $("input[name=foo]", container); var bar_input = $("input[name=bar]", container);
i want bind event handler both inputs. hoped work:
$([foo_input, bar_input]).on("keypress", function() { /* ... */ });
but alas, no. there convenient way of gathering multiple jquery objects 1 purposes this?
use in add() in jquery adding jquery object
foo_input.add(bar_input).on("keypress", function() { /* ... */ });
Comments
Post a Comment