Creating Elements with classes? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

Creating Elements with classes?

So I'm trying to create a div that has the same styling as the example message. (name isn't actually required) However, I need this div to be created via JS. I'm trying to make a messaging program(that won't actually ever work as a REAL messaging app like discord or kik. Just for funzies.) but I can't seem to figure out how to actually CREATE the messages. If I'm doing it wrong, please let me know. As for now, I'm pretty sure it's done with createElement, but I could be wrong. https://code.sololearn.com/W84mxAR64Gc5/?ref=app

5th Aug 2018, 7:13 AM
Daniel Cooper
Daniel Cooper - avatar
7 Respostas
+ 8
A basic example on how to create it and apply the styling. I'll leave the events like creation of the div on button clicks to you ^_^ .If you have problems, feel free to ask ^^ https://code.sololearn.com/WEBHw2O2T6cE/?ref=app
5th Aug 2018, 7:51 AM
Nikhil
Nikhil - avatar
+ 10
Daniel Cooper Just add this in the end of function Send() ~ MessageInput.value = ""; or var msg_input = document.getElementById("MessageInput"); msg_input.value = ""; A simple fix....
5th Aug 2018, 8:24 AM
Nikhil
Nikhil - avatar
+ 10
Daniel Cooper then you should "actually" make the position fixed I think..Give some values for top and left too like ~ #InputContainer{ position:fixed; left:10px; top:10px; }
5th Aug 2018, 8:34 AM
Nikhil
Nikhil - avatar
+ 1
5th Aug 2018, 8:14 AM
JME
+ 1
Nikhil I got it to work right after sending that. Lol. Thanks
5th Aug 2018, 8:25 AM
Daniel Cooper
Daniel Cooper - avatar
+ 1
I do have one more question. It's something I've had trouble with before. When setting the InputContainer position to fixed, it appears over the first message. How can I fix this?
5th Aug 2018, 8:30 AM
Daniel Cooper
Daniel Cooper - avatar
0
https://code.sololearn.com/W84mxAR64Gc5/?ref=app Working version, however I still can't get the input to clear on send.
5th Aug 2018, 8:21 AM
Daniel Cooper
Daniel Cooper - avatar