Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery: using two selectors for one .click event?

If I have something like this:

$(".jq_elements").children("input").click(function()

How do I add another selector to it, so that same event gets fired up when either one is clicked.

Basically something like this would be needed:

$(".jq_elements, .jq_another_div").children("input").click(function()

Is something like this possible?

edit: I did try this the way that I described above. Turns out my code was a bit crooked, but its fine now.

like image 478
WraithLux Avatar asked Feb 02 '11 21:02

WraithLux


People also ask

Can we use multiple selectors in jQuery?

You can specify any number of selectors to combine into a single result. This multiple expression combinator is an efficient way to select disparate elements. The order of the DOM elements in the returned jQuery object may not be identical, as they will be in document order.

Can you chain jQuery selectors?

Can you chain selectors in jQuery? With jQuery, you can chain together actions/methods. Chaining allows us to run multiple jQuery methods (on the same element) within a single statement.

How do you select multiple selectors?

To select multiple elements of an html page using multiple elements selector, we pass the element names inside parenthesis, in double quotes, separated by commas. For example: $(“div, p, h2”) this will select all the div, p and h2 elements of a page.

How many jQuery selectors are there?

So far we have covered only three standard jQuery Selectors. For a complete detail of all these jQuery selectors, you can go to through jQuery Selectors Reference.


1 Answers

$("selector, selector")

That very syntax works. Do you want to call .children("input") on both?

Alternatively $.merge($("selector"), $("selector"));

like image 52
Raynos Avatar answered Nov 09 '22 12:11

Raynos