how to change/edit value of label with jquery/javascript?
19,276
You don't need the jquery.
To made almost all tag elements editable set the contentEditable
to true
.
So, you can change using the default features of a HTML.
Author by
r.r
Updated on June 05, 2022Comments
-
r.r almost 2 years
i have a standart html label with value:
<label id="telefon" value="101"></label>
i like to edit this value by clicking on the label and enter on the appeared textbox new value (like
value="202"
).how can i do such a tricky thing?
i tried it with JQuery function, but it really dont wont to work:
$(function() { $('a.edit').on("click", function(e) { e.preventDefault(); var dad = $(this).parent().parent(); var lbl = dad.find('label'); lbl.hide(); dad.find('input[type="text"]').val(lbl.text()).show().focus(); }); $('input[type=text]').focusout(function() { var dad = $(this).parent(); $(this).hide(); dad.find('label').text(this.value).show(); }); });