I am attempting to get a prompt value to attach to an unordered list and I cannot seem to get it to work.
My button is:
<button onclick="nameP()">PLEASE CLICK</button>
Here is my jQuery/Java code:
function nameP() {
var name = prompt("Please enter your name");
document.getElementById("a").innerHTML = name;
$('#a').appendTo('ul')}
my unordered list is
<ul></ul>
thank you for any help
You're trying to get the value from the anchor tag, that i'm not sure what it contains. But the code below will work as you want. It will take the name from the prompt box and then append that text to the unordered list
function nameP() {
var name = prompt("Please enter your name");
$('ul').append(name)
}