i want to copy the input from a user to multiple div’s.
I tried to use .each() because i want to apply it to every div that follows.
I wrote this code so far, but it’s only working for the first div.
<input type="text" name="someText" id="someText">
$("#someText").keyup(function() {
var x = $("#someText").val();
$("#copy").each(function () {
$(this).html(x);
});
});
<div id="copy"></div>
<div id="copy"></div>
Best Regards,
Felix
IDs have to be unique:
Most browsers will return the first element of a document with a given ID, though the behaviour is unspecified.
Use classes instead if you want to select multiple elements:
HTML:
JavaScript:
Some other points:
.each, setter methods are normally always applied to all elements of the set.thisrefers to the element the handler is bound to. You don’t have to use the selector again.