The following function can help you, using JQuery
you get the value of label
and input
by means of your id
, you assign the value of input
to label
each time do click
on the button:
function addLoadEvent() {
var nombre1 = $('#lbltipAddedComment').text();
var nombre2 = $('#lbltipAddedComment2').val();
$('#lbltipAddedComment').text(nombre2);
};
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<html>
<body>
<label id="lbltipAddedComment">Nombre</label>
<input type="text" id="lbltipAddedComment2">
<button id="lbltipAddedComment3" onclick="addLoadEvent()">Click!</button>
</body>
</html>
I commented to you that your code did not work because what you should get from label
is the text by means of textContent
and input
you are not getting the valor
by means of .value
.
I'll leave the code without JQuery in case you need it:
function addLoadEvent() {
var nombre1 = document.getElementById("lbltipAddedComment").textContent;
var nombre2 = document.getElementById("lbltipAddedComment2").value;
document.getElementById("lbltipAddedComment").textContent = nombre2;
};
<html>
<body>
<label id="lbltipAddedComment">Nombre</label>
<input type="text" id="lbltipAddedComment2">
<button id="lbltipAddedComment3" onclick="addLoadEvent()">Click!</button>
</body>
</html>
I hope it helps you. Greetings.