Help


#1

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?


#2

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)

you could give your added paragraph an id attribute, then use Javascript to see if it exist, if it exist, remove the element with that id, else add it.

There are plenty of options


#3

I’m very very inexperienced with javascript, and I really only need it here to add a textnode, and then limit it. I’ve tried doing some javascript, but it doesn’t make sense to me. I understand if this isn’t possible, but I’d like a written example, rather than an explaination. It doesn’t make sense to me, so yeah.


#4

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 null


#5

I really don’t have much of an interest in javascript either. As said, I’ve taken a course about it before on here, and it didn’t make sense to me. And now I’m at the point where I don’t really have any need for it, but in this one instance, I do.


#6

What do you except of me or the codecademy community then?


#7

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…


#8

Giving full on code answers without explanation is a violation of the guidelines

We do explain :slight_smile:

Like i tried explain, we could an id attribute to your para which you create with Javascript. Then we can use this 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.

additional information:
https://stackoverflow.com/questions/9422974/createelement-with-id
https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById


#9

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…


#10

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.


#11

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.


#12

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:

https://developer.mozilla.org/en-US/docs/Web/API/Element/setAttribute


#13

What exactly is a para element??


#14

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


#16

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?


#17

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.


#18

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.


#19

you do know what HTML is? Its the document that makes up the webpage. This is called DOM (document object model), we can use Javascript to manipulate the DOM (the document/the html if you like)

the thing is, DOM manipulation is expensive (processing power), so we want to keep the DOM manipulation minimum.

so, first we create a paragraph element with javascript, that is this line:

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:

document.getElementById("myDIV").appendChild(para);

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


#20

I am 14 years old. I don’t have any sort of money. Besides, I wouldn’t hire anything for a school project.


#21

then ask your teacher for help or your fellow classmates for that matter, and start learning Javascript.