动态输入文本到Label

Input text into Label dynamically

我注意到这个问题已经被问过几次了,但我找不到适合我的问题的解决方案。

我正在尝试使用 jQuery 将文本动态添加到我的标签中。我可以看到文本已添加到检查元素中,但这并未反映在 UI.

使用以下任一方法添加文本后:

$("#selection").text("My Text Here");
$("#selection").html("My Text Here");
//document.getElementById("selection").textContent = "My Text Here"

生产

<input type="text" id="selection" name="properties[Selection]">My Text Here</input>

但 UI 仍然存在

尝试使用 .val()

$("#selection").val("My Text Here")

$("#selection").val('My New Text Here');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="selection" name="properties[Selection]"/>

Please note : <input> is a self closing tag and there isn't any </input> for it rather it should end with <input/>