Ajay Yadav
Ajay Yadav

@ATechAjay

10 Tweets Jan 26, 2023
📢 Insert elements using "insertAdjacentHTML( )" method in JavaScript💡
A Thread 🧵
🍭 insertAdjacentHTML( ):
❍ The insertAdjacentHTML( ) method is used to insert elements to the webpage at particular positions.
🍭 Syntax:
❍ The insertAdjacentHTML() method accepts 2 parameters.
1️⃣ Position
2️⃣ html
1️⃣ Position
❍ There are four types of positions that can be accepted by insertAdjacentHTML() at a time.
1. beforebegin: Before the element
2. afterbegin: After the beginning of the element
3. beforeend: Before the end of the element
4. afterend: After the end of the element
2️⃣ html
❍ The HTML code which you want to insert on the webpage.
Example:
❍ Suppose, we want to insert our elements near to "ul" element.
❍ We will insert 4 elements on every position of the "ul" element.
❍ So, we are going to insert a string that is stored in the "afterbeginInsert" variable.
❍ Now we need to select the element, near which we are going to insert, it is the "ul" element.
❍ And finally, call the method and pass both parameters to this method.
❍ Similarly, we can insert the element on each position of insertAdjacentHTML( ) method.
😊 Try it from here:
codepen.io
That's all for now, we will meet in the next thread😍
🔔 Follow Me @ATechAjay
For:
🌐 Web Development
✨ JavaScript
⚛️ React JS
📝 Writing Skill
🔥 Motivation
💹 Growth
⛔ But Not For Only Resources & Shitpost 😁
Thank you so much for staying to the end of this thread💚
New YouTube video 😊

Loading suggestions...