I'm very new to JavaScript. Here is my html page.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<header>
<h1>This is my site!</h1>
</header>
<section>
<h2>My site content</h2>
<input type="text" id="name">
<button id="addName">Submit</button>
<hr>
<p>name</p>
</section>
<script src="http://code.jquery.com/jquery-2.1.3.min.js"></script>
<script>
var myName = $("#name").val();
$("#addName").click(showName(myName));
function showName(value) {
$("p").html(value);
};
</script>
</body>
</html>
I want to type something in the textfield and click the submit button to change text in the <p>
. But It doesn't work the way I want. What am I doing wrong?
Sorry for my bad English.