my text does not apear on the screen after I enter it in on javascript prompt

user2563349

hey guys doing this tutorial again on JavaScript. I noticed that when I click the button I don't see any text after I enter in the new items. Do any of you know why. The border is there from my css so I know its being entered in, anyway here is my code so far.

<!doctype html>
<html>
    <head>

    <title>To do list with html and javascript</title>
    <style>
    ul { list-style: none; padding: 0; margin: 0; width: 400px;}
    li { border: 4px solid #ccc; background: #eee; padding: 10px 15px; color: #000; }
        </style>
    </head>
    <body>
<h1>To Do List</h1>
<p><button id="btnAdd">click here!</button></p> 

<ul id="todolist">
</ul>

</ul>


<script src="todo.js"></script>
    </body>
</html>

and

function addNewItem(list, itemText){
    var listItem = document.createElement("li");
    listItem.innerText = "itemText";


    list.appendChild(listItem);
}


var btnNew= document.getElementById("btnAdd");
btnNew.onclick = function() {
    var itemText = prompt("what is your task?")
    addNewItem(document.getElementById("todolist"), itemText);
};
The Dark Knight

Your html mark up is wrongly posted . There is an extra ul there.

More over the js code must be like :

function addNewItem(list, itemText){
    var listItem = document.createElement("li");
    listItem.innerText = itemText;
    list.appendChild(listItem);
}

var btnNew= document.getElementById("btnAdd");
btnNew.onclick = function() {
    var itemText = prompt("what is your task?")
    addNewItem(document.getElementById("todolist"), itemText);
};

Next find the working solution in this fiddle : http://jsfiddle.net/LRyKd/1/

When you give itemText as 'itemText' then itemText becomes a string and that constant string gets appended instead of the text you are entering. That's why it was not working for you .

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

I want to display my text after my thumbnail slider div

분류에서Dev

Why is my ssh connection dropping immediately after I enter my password?

분류에서Dev

How does "less" switch to the text, then back to the prompt?

분류에서Dev

How do I prompt a user until they enter a valid integer?

분류에서Dev

How can I automate inputting text into a prompt?

분류에서Dev

How can I display text from a file automatically after powering up my computer, in text editor or terminal?

분류에서Dev

14.04 unity does not start after login screen

분류에서Dev

How do I fix my prompt in emacs shell-mode?

분류에서Dev

How can I change my number validation from a form to a prompt?

분류에서Dev

How can I shorten my command line (bash) prompt?

분류에서Dev

Is it posible to pick a date or put text on one input and automatic should apear on other one too

분류에서Dev

Why does my screen dim on a desktop installation of Windows 7?

분류에서Dev

Why does my boot screen list several kernel versions?

분류에서Dev

Why does light-locker keep the screen black after unlock?

분류에서Dev

How do I crop my screen's working area?

분류에서Dev

bash prompt user to edit string and enter

분류에서Dev

How do I fix Unity from freezing and artifacts on my screen when I'm charging my laptop?

분류에서Dev

Why does my JavaScript instances return the same?

분류에서Dev

I want my disabled text will be the placeholder for my select box

분류에서Dev

How does "man" restore the screen when I quit the program?

분류에서Dev

javascript does not function after dom is updated

분류에서Dev

Using Selenium/WebDriver and Python, how do I suppress the prompt to share my camera and microphone?

분류에서Dev

Why does one of my two Dell monitors unexpectedly enter power save mode when using DisplayPort daisychaining?

분류에서Dev

How do I manually boot from the grub prompt after do-release-upgrade?

분류에서Dev

Javascript Prompt keeps appearing

분류에서Dev

Why is Terminal automatically executing my command after pasting text?

분류에서Dev

Screen locker doesn't prompt for password

분류에서Dev

How do I add this jQuery into my Javascript?

분류에서Dev

How can I wire up a button on my page so that it is clicked when a user presses enter?

Related 관련 기사

  1. 1

    I want to display my text after my thumbnail slider div

  2. 2

    Why is my ssh connection dropping immediately after I enter my password?

  3. 3

    How does "less" switch to the text, then back to the prompt?

  4. 4

    How do I prompt a user until they enter a valid integer?

  5. 5

    How can I automate inputting text into a prompt?

  6. 6

    How can I display text from a file automatically after powering up my computer, in text editor or terminal?

  7. 7

    14.04 unity does not start after login screen

  8. 8

    How do I fix my prompt in emacs shell-mode?

  9. 9

    How can I change my number validation from a form to a prompt?

  10. 10

    How can I shorten my command line (bash) prompt?

  11. 11

    Is it posible to pick a date or put text on one input and automatic should apear on other one too

  12. 12

    Why does my screen dim on a desktop installation of Windows 7?

  13. 13

    Why does my boot screen list several kernel versions?

  14. 14

    Why does light-locker keep the screen black after unlock?

  15. 15

    How do I crop my screen's working area?

  16. 16

    bash prompt user to edit string and enter

  17. 17

    How do I fix Unity from freezing and artifacts on my screen when I'm charging my laptop?

  18. 18

    Why does my JavaScript instances return the same?

  19. 19

    I want my disabled text will be the placeholder for my select box

  20. 20

    How does "man" restore the screen when I quit the program?

  21. 21

    javascript does not function after dom is updated

  22. 22

    Using Selenium/WebDriver and Python, how do I suppress the prompt to share my camera and microphone?

  23. 23

    Why does one of my two Dell monitors unexpectedly enter power save mode when using DisplayPort daisychaining?

  24. 24

    How do I manually boot from the grub prompt after do-release-upgrade?

  25. 25

    Javascript Prompt keeps appearing

  26. 26

    Why is Terminal automatically executing my command after pasting text?

  27. 27

    Screen locker doesn't prompt for password

  28. 28

    How do I add this jQuery into my Javascript?

  29. 29

    How can I wire up a button on my page so that it is clicked when a user presses enter?

뜨겁다태그

보관