Jump to content

Quick Javascript Exercise Help!


RawrRawrRob
 Share

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 comment
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 comment
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 comment
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 comment
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 comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...