I'm trying to append an input text field and its value to be the value of a div.
Here is what I came up so far:
$(this).append('<input type="text" value=' $('#div1').val() '>');
You can't place any element inside an input. An input does not contain any HTML.
To append an element with a text message when the input field is changed, change() and appendTo() methods are used. The change() method is used to detect the change in the value of input fields.
Don't use HTML strings for everything!
$(this).append(
$('<input>', {
type: 'text',
val: $('#div1').text()
})
);
$(this).append('<input type="text" value='+ $('#div1').html()+ '>');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With