I have a problem getting the id element to show in the <p>
. Below is my sample coding, it cannot show my id element in the <p>
. Hope someone can guide me on which part I a getting wrong. Thanks.
<!DOCTYPE html>
<html>
<body>
Name: <input id="try" type="text" value="testing"><br>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = $('#try').attr('id');
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
Actually, I want the expected result like below the picture: