How to change shortcut text in jQuery?

I have a text box and a shortcut. If the user wants to change the label text, he will have to enter the text in the text box. How to update the text of labels every time the user makes an entry in the text field when changing?

I know that you can use AJAX with jQuery and PHP. Is there an easier way? Please let me know. Here is my code and link: http://jsfiddle.net/uQ54g/1/

$('#change1').change(function(){
    var l = $(this).val();
    $('label').replaceWith(l);


});
+3
source share
5 answers

, .text .html, jquery. . , . , , , .

HTML:

<input type="text" id="change1"/><br/>
<label id="test">Hello</label>

JavaScript:

$('#change1').change(function(){
    var l = $(this).val();
    $('#test').text(l);
    // OR $('#test').html(l);
});

, keyup change.

jsfiddle

+2

, , keyup

$('#change1').keyup(function(){
var l = $(this).val();
$('label').text(l);
//alert($('#change1').val())
});

http://jsfiddle.net/uQ54g/4/

, replaceWith , label <label>hello</label> Changed Text, , $("label") undefined,

+2

try the following:

$('#change1').keyup(function(){
l=$(this).val()
$('label').html(l)
})
+1
source

use this with jquery library

$('#change1').on('keyup',function(){ //Change1 is id of textbox
   $('#label1').html($(this).val()) //label1 is the id of the label
});
$('#change1').blur(function() { //if we copy paste some text into the textbox it will also work if use this blur and trigger function
   $(this).trigger('keyup');
});
+1
source

How about this

$('#change1').change(function(item){
     $('label').text(item.target.value);
});
0
source

All Articles