Sachin Prasad Sachin Prasad - 2 months ago 9
HTML Question

Replace an input value next to span element

I have to this input:

<input type="text" id="my_input" />


After a user enters anything in the input I have to append this next to the span.

<p id="patient_provider" >
<span>
Name
</span>
Sam
</p>


The code I used is(It should be something like below):

$("#patient_provider").html($('#patient_provider').children()[0]+$('#my_input').val());


But this is not working.

It is showing something like:

[object HTMLSpanElement] Sam


Also please note :

There are some css implemented on the span directly and I can not add another span

Answer

$('#patient_provider').children()[0] is an element and is converted to a [object HTMLSpanElement] string

The right is:

 $("#patient_provider").html($('#patient_provider').children()[0].outerHTML+$('#my_input').val());