Jump to content

Quick Javascript Exercise Help!


Recommended Posts

I can help but I don't want to download, open, and run the contents of this zip. Someone else may be willing to but if you describe the problem I can help.

Link to post
Share on other sites
I can help but I don't want to download, open, and run the contents of this zip. Someone else may be willing to but if you describe the problem I can help.
Here's what the HTML file looks like in the browser, with 3 instructions on the right link The button's id is "btnList" Edited by RawrRawrRob
Link to post
Share on other sites
We're happy to help you learn how to do this, but we aren't going to do your schoolwork for you. What do you have so far? What questions do you have?
This is what I have so far,
window.onload = init; function init(){document.querySelector("#btnList").onclick = addList;} function addList(){//this creates the paragraph to add to #listContentvar p = addParagraph(); //append the var pdocument.querySelector("#listContent").appendChild(p);}

I'm wondering how I get the text from the input filed into the #listContent div. You don't need to give me the code, I just need an explanation and I can then try to figure things out myself, I appreciate the help!

Link to post
Share on other sites

All form elements have a value property. For a text input, the value property contains the user text. All HTML elements have an innerHTML property. You can assign a plain text string or a string containing HTML to this property, and it will become part of the element. Some purists don't like to use this, but it requires very little code and is backward compatible with older browsers.

Link to post
Share on other sites
All form elements have a value property. For a text input, the value property contains the user text. All HTML elements have an innerHTML property. You can assign a plain text string or a string containing HTML to this property, and it will become part of the element. Some purists don't like to use this, but it requires very little code and is backward compatible with older browsers.
Thank you, this helped! This is what I have so far now and it adds the text to the list window.onload = init; function init(){document.querySelector("#btnList").onclick = addToList; } function addToList(){ var textbox = document.getElementById('txt');var content = document.getElementById('listContent'); var addtext = document.createElement('li'); addtext.value = textbox.value;addtext.innerHTML = textbox.value;listContent.appendChild(addtext);} Now, how do I get it so when you add the text, it also adds a span class (in my case the class is called "remove") infront of the text to the list? Edited by RawrRawrRob
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...