#[m3 - interactive-websites "We are the Champions" Project] Problems with `.createElement()` and `p`

4 messages · Page 1 of 1 (latest)

dusk badge
#

Is it recommended to only use ul li for .createElement() ? I've been building the "We are the Champions" project using 'p' elements for the recommendations up to now, but this seems to produce issues in that I can't do it through .createElement() method. It seems to me that this can only be done with document.createElement('p') (attempting it through this route led to no visible results on the page) , and not, for example, the div that I have set up to hold the endorsements (endorsementsDiv.createElement('p')).

Being that I can't create it through this method, I am only left with the option (to my knowledge) of concatenating new elements through the 'endorsementsDiv.innerHTML += <p>${endorsement}</p>' route, meaning I can't set up an event listener for each added p element (an event listener isn't really necessary, I just want to nail down the concepts introduced previously).

Am I maybe missing something here? Maybe I messed up somewhere? Keep in mind that everything I have written/tried was not left in the provided scrim.

Scrim link: https://scrimba.com/scrim/czMVM6tM

hoary mist
#

The only obvious issue I see here is the fact that createElement() doesn't add to the DOM... you need to add it to container where you want it to live.

In your case you probably need this:

endorsementsDiv.appendChild(newP)

(NOTE: you have other problems on this page but at least this line of code should add the element)

Does that clear up the situation for you?

dusk badge
# hoary mist The only obvious issue I see here is the fact that createElement() doesn't add t...

Thank you for the advice! This seems to have fixed the problem - now I'm on to take a swing at the stretch goals.

Also, apologies for getting back to you late! I made the post right before bed, and I've finally finished my work day.

If it isn't too much trouble, I would love to hear more about the other problems on my page that you have mentioned. I'm still very early in my study and I haven't had any real feedback from anyone at this point, so I think every little bit will help 🙂

hoary mist
#

Sure. So the next problem is that after you click the Publish button, the endorsement is added (yay!) but you get an error: "cannot read properties of undefined (reading '0')"

Also, you should clear the text box as part of the publish function.

There are a couple of things to tackle for now.