how to change/edit value of label with jquery/javascript? -


i have standart html label value:

<label id="telefon" value="101"></label> 

i edit value clicking on label , enter on appeared textbox new value (like value="202").

how can such tricky thing?

i tried jquery function, dont wont 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();   });  }); 

http://jsfiddle.net/jasuc/ , since didnt provide markup, take working example

$(document).on("click", "label.mytxt", function () {     var txt = $(".mytxt").text();     $(".mytxt").replacewith("<input class='mytxt'/>");     $(".mytxt").val(txt); });  $(document).on("blur", "input.mytxt", function () {     var txt = $(this).val();     $(this).replacewith("<label class='mytxt'></label>");     $(".mytxt").text(txt); }); 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -