Skip to content
Advertisement

Inserting elements using javascript into html

I wanna ask that is there any way to insert html content using javascript in such a way like i have a table and inside there is a tbody and inside that i am inserting element using javascript like i am inserting tr and inside that tr i am inserting 5 td and i want that 5 td to have different content and if you try to put all the above stuff in code it will look something like this

JavaScript

and challenge for me is to insert different content in td inside same tr. And after that final html code should look like this :-

JavaScript

and after that i will generate more tr like this.

Hope you understand my problem and help me!

Advertisement

Answer

Actually the same example as @b3hr4d but u shouldn’t use .innerHTML on plain text, choose between .textContent and .innerText. Good luck =)

JavaScript

result

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement