You can target all the inputs, or just give them a common class to target and extract something, I used the class, but the data attributes would be easier if the elements had several classes, etc .:
$('input').on('keyup', function() { $('.'+this.className).html(this.value); });
Fiddle
EDIT:
as noted above, if elements have multiple classes, use data attributes:
<input class="input" data-id="apple" > <input class="input" data-id="orange" > <input class="input" data-id="banana" >
Js
$('.input').on('keyup', function() { $('.' + $(this).data('id')).html(this.value); });
Fiddle
adeneo Jul 10 '13 at 14:30 2013-07-10 14:30
source share