i would recommend watching the other video this person made link: ua-cam.com/video/VW8kNAous88/v-deo.html which teaches how to dynamically create elements, but basicly in the video he writes line of code document.body.appendChild([here Is variable that contains the element]); the important part Is the 'body', this part of the code specifies where the element Is gonna be created, but it has to be a variable for example you want to create new element in div that has id: beforeTest So what u gonna type Is let div = document.getElementById("#beforeTest") And then u gonna type document.div.appendChild(....)
Cheers mate! I don't think there are many scenarios where you'd want to use the createAtrribute method, I would just stick with setAttribute as it's much shorter to write
This is by far the best playlist for DOM interaction using JS. Great work brother 👏👏👏👏👏
This is exactly what I was looking for (needed to get a form’s input field to autopopulate with the page’s name)! Thank you!
You are great man! Love form India.. ❤️
you are best! this is only Dom tutorial in youtube which have more important details
Yoww Man!! I am so thankful right now hahaha Bless you!
Oh, muchas gracias dcode! this is exactly what I was looking for
Keep going on ! 🔥
Great as always
Can we use this on span element? I need to set the value for span element which is used as label actually..
Love your tutorials... thank you
Thanks man for the clear explanation
You're very welcome 🙂
Man. that was great. You just helped me thanks man
😎👏👍
that was super clear
Thanks for your tutorial.
awesome explanation..
Hi,
I would like to put dynamically created element in specific place on page, for example before the div with class .test. How Can I do that?
i would recommend watching the other video this person made link: ua-cam.com/video/VW8kNAous88/v-deo.html which teaches how to dynamically create elements, but basicly in the video he writes line of code document.body.appendChild([here Is variable that contains the element]); the important part Is the 'body', this part of the code specifies where the element Is gonna be created, but it has to be a variable for example you want to create new element in div that has id: beforeTest So what u gonna type Is let div = document.getElementById("#beforeTest") And then u gonna type document.div.appendChild(....)
can I change the innerHTML of a div by using the setAttribute ?
Nope, you need to use `innerHTML` for that.
easy to understand ,,, thx
Great video
Well explained. Thanks 👍
All good!
how to change css of a dynamically created element in javascript? I am not able to get the element either by id or class.
You can change the CSS by saying element.style.fontWeight = "bold"; for example
With input tag you don't have to use setAttribute function - you can just type: querySelector('#myInput).value = 'HELLO'
Hah this is better, thanks for this
did I hear that your name is DOM ?
Nah mate, where did you hear that from?
@@dcode-software
0:00
@@saadshahrour3286 Yup😂
Heard the same XD
Was going to comment "I love you Dom!" here
well explained
Great video! can u explain to me when to use setAttribute and when instead createAttribute plus setAttribute . thanks a lot
Cheers mate! I don't think there are many scenarios where you'd want to use the createAtrribute method, I would just stick with setAttribute as it's much shorter to write
@@dcode-software for some reason when I did setAttribute and gave name and value that didn't show up inside my body. Any specific reason
I Get This Error In The Console!: "Uncaught TypeError: Cannot read property 'setAttribute' of null"
That means that your computer doesn’t support setAttribute
Nice