-5

How can i set value for each #path (not only for first)?

<input id="path"/>
<input id="path"/>

Code:

$('#path').each(function() {
    $('#path').val("123");
});
Arriba
  • 305
  • 2
  • 3
  • 14
  • 10
    Id's need to be unique – Mouser Aug 10 '15 at 13:52
  • 4
    I'm voting to close this question as off-topic because it's an XY problem – Denys Séguret Aug 10 '15 at 13:54
  • 1
    possible duplicate of [Can multiple different HTML elements have the same ID if they're different types?](http://stackoverflow.com/questions/5611963/can-multiple-different-html-elements-have-the-same-id-if-theyre-different-types) – Mouser Aug 10 '15 at 13:57

1 Answers1

1

Id should be unique, use a class instead.

<input class="path"/>
<input class="path"/>

$('.path').val("123");

And when you are setting a common value by using a class selector, there is no need to iterate.

Rajaprabhu Aravindasamy
  • 66,513
  • 17
  • 101
  • 130