0

I came across the following code in JQuery which I'm not familiar with

$('*[name=\'' + child.Name + '\'],[id=\'' + child.ID + '\']');

I have two different divs(different IDs) containing two input elements with same name. When I pass the name and ID to the above query, I get both the input elements.

I found this on Stack Overflow, but if what is mentioned there is correct, I should be getting the element with in the div which I pass.

I want to know how this would work:

$('[name=""],[id=""]');

Thanks in Advance.

Zac
  • 1,305
  • 3
  • 17
  • 28
Ram Venkat
  • 84
  • 1
  • 10

1 Answers1

1

This is described in the jQuery documentation on Multiple Selector:

Multiple Selector (“selector1, selector2, selectorN”)
Description: Selects the combined results of all the specified selectors.

The other question you linked to is about the syntax:

$("selector1", "selector2")

That's an example of the jQuery(selector, context) syntax described here, which is equivalent to jQuery(context).find(selector).

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Thanks for quick reply, I can't change the code as it is from the production library. I just wanted to know what "," does in the selector. – Ram Venkat Nov 16 '17 at 08:57
  • 1
    Sorry, I thought you were asking how to get the second effect. I've rewritten my answer to more directly address your actual question. – Barmar Nov 16 '17 at 16:24