How to update with jquery the label of preview div when im typing inside of the parent input of edit div? Thank you.
<html>
<body>
<div id="preview">
<label id="panyName" class="workExperience">
This is my pany
</label>
</div>
<div id="edit">
<label>Company Name: </label>
<input type="text" id="panyName" />
</div>
</body>
</html>
How to update with jquery the label of preview div when im typing inside of the parent input of edit div? Thank you.
<html>
<body>
<div id="preview">
<label id="panyName" class="workExperience">
This is my pany
</label>
</div>
<div id="edit">
<label>Company Name: </label>
<input type="text" id="panyName" />
</div>
</body>
</html>
<input />
element isn't parent to anything.
– Richard JP Le Guen
Commented
Aug 11, 2010 at 19:33
keyup
doesn't react to pasting with the mouse and change
doesn't update "as-you-type".
– Stephen P
Commented
Aug 11, 2010 at 20:05
You'd have to have something along these lines in your code:
<script>
$("#panyName").keyup(function () {
var value = $(this).val();
$(".workExperience").text(value);
}).keyup();
</script>
However, I would NOT give them the same id value, as it might lead to some errors.
Good luck!
you can not have the same ID in the tag "label" and the tag "input".
<div id="preview">
<label id="panyName" class="workExperience">
This is my pany
</label>
</div>
<div id="edit">
<label>Company Name: </label>
<input type="text" id="panyNameInput" />
</div>
$(document).ready(function(e){
$('#panyNameInput').bind('change', function(ev) {
$(this).closest('#edit').prev().find('#panyName').html($(this).val());
});
});
test