I am starting up with Jquery and would like to do the following:
Submit and store a text with Jquery, and replace the text in the HTML with this.
How do I exactly do this?
<section>
<label for="name">Name</label>
<input type="text" id="name">
<input type="submit" id="submit">
<p class="output">Hello <strong>Text that needs to be replaced</strong></p>
</section>
I tried something like:
$(function () {
$( "#name")
.on ("submit", function() {
let value = $(this ).val();
$("strong").text( value );
});
});
But this didn’t work. How can I achieve this?
2
Answers
You have several mistakes in your javascript, it should be
Try this code:
Test it here