Okay. So if I write this code:
then how would I limit the button to only writing the text once, and making it so that the next time I click the button, it removes the pasted note?
Okay. So if I write this code:
so many options, you could add a class to your button to keep track of adding or removing (change classes when the button is pressed)
There are plenty of options
which is exactly why you need to solve this problem in order to learn from it. Lets start by adding an id to your
para, see here:
then we could use
document.getElementById to see if the element exist, if it doesn’t, getElementById will return
What do you except of me or the codecademy community then?
I expect help, as in it being written out and not just explained. I just need to know this one, nothing else… But my guess is that you’re like stackoverflow, not giving the answer or explaining it, but only being used to help fix code… And if that’s the case, then I really have no idea on where to look anymore for help…
Giving full on code answers without explanation is a violation of the guidelines
We do explain
Like i tried explain, we could an
id attribute to your
id (ids can identify unique elements) to see if the paragraph exist on the page, with the help of document.getElementById.
this function returns the element if it exist on the page, or null if not. With a simple
if/else, we could then add or remove the paragraph as you wish.
The thing with your question is, forums like codecademy or stackoverflow mostly do questions where users try to implement a solution, and get stuck. In your case, you haven’t yet decided on the solution you want to implement.
On stackoverflow, its very likely you simple get downvotes, given we can’t see you put effort into finding a solution to your problem. I understand the people on stackoverflow in that matter, having been on the helping side of things here.
ideally, i should take a step back: what solutions have you researched or come up with? And then help you from there.
And as I’ve stated, I don’t need an explaination, I need the code… I don’t understand this. Where to add it, what to do, etc… I just want the answer… I’ve been trying to find someone who will just give me the code for 3 days now, and I’m close to giving up… It doesn’t make sense to me, and I just want the answer…
that is the problem, programmers are generally very helpful. Programmers share huge amount of data and information with each other, helping out where possible
however, coming up with a solution, fully implementing the solution, that is a programmers job. Its what they get paid for. They invested huge time into learning all these things, and then someone asks them to do it for free. That is where the help stops, and why you haven’t been able to find someone to help you for the past 3 days
And you are going to hate me for this, or at least disagree with me, if you say you want the solution, and you do not care about learning, you will get very little help. Programmers have a learning mentally (well, most of them). So, the way you ask the question is against there nature.
I will happily help you (look at my forum activity, i helped countless people) but you will have to implement the solution and learn along the way. Which is the first option
the second option, is to hire a developer to the job for you.
I have been trying to be truthfully, and hopefully not offending.
Let me say it in a different way then. I learn much easier by looking at things, than by getting it explained. If you told me how to impliment a div file for example, told me how to do the class, gave it properties and so on, sure, I might understand a little tiny bit of it, but if I can see how it works, it’s much easier for me to understand, because I can see how it links together. Hopefully this explains it a little better for you.
Maybe, but this approach doesn’t work for learning to implement solutions. Which is key in programming.
Yea, i can give you the code, you look at it, and i am sure you will be able to understand it, but you haven’t learned the most important skill of them all.
the stackoverflow question i linked to, did you even look at it? It literally tells you the line of code (some names need to be different) you need to implement. And i told you, you want do to do this to your
para element in JS.
Do you want my help (my way)? I already took one step away from you, which is figuring out how to solve the problem, i can walk you through the steps, but you have to start with implementing setAttribute. Feel free to look at MDN as well if you need more help with this function:
What exactly is a para element??
sorry, i meant para variable which you defined here:
var para = document.CreateElement("P");
which creates an html paragraph element. Which sparked my confusion for a second
https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_document_createelement4 I just took it from here, because once again, I’m trying to figure this out, but it doesn’t make sense. The only thing I changed putting the button into the div and setting a linebreak after the first message, so that the button would go under the message.
these 4 lines:
var para = document.createElement("P"); var t = document.createTextNode("This is a paragraph."); para.appendChild(t); document.getElementById("myDIV").appendChild(para);
how far do you understand them? Can you explain to me what they do?
This is just guessing, because I only have an idea of it. The var t creates the node when the button is clicked, the para variable I don’t understand, and by that I don’t understand the para.appened, and the document.getelementbyid doesn’t make sense to me either.
But if I had to say my honest opinion on this, then I’ll say it like this: I just want it done. I just need it done to do one simple thing, having a button that can add, and remove, a description of a video. That’s all I want. I hope it doesn’t sound like I’m being selfish or anything, but I’ve just had enough of this.
the thing is, DOM manipulation is expensive (processing power), so we want to keep the DOM manipulation minimum.
var para = document.createElement("P");
this has no interaction with our webpage yet!
then we create text for our paragraph:
var t = document.createTextNode("This is a paragraph.");
now we want to add the text to the paragraph:
para.appendChild(t); # add text(node) to paragraph
now we have the paragraph, now we need to add it to our webpage document, which is what we do here:
getElementById gets the
<div id="myDIV"> which you defined in html, and add the created paragraph to the webpage.
then hire a developer, that can’t be an expensive to let that build
I am 14 years old. I don’t have any sort of money. Besides, I wouldn’t hire anything for a school project.