Dynamic Creating Elements Using Javascript
So I have created elements in my html using javascript. The only problem is that my button is not showing up. Following is my code: var search_div1 = document.createElement('div');
Solution 1:
You're using .appendChild()
incorrectly. For example, this line of code:
search_input.appendChild(search_span);
Is trying to make a <span>
a child of an <input>
. That is not legal HTML.
Remember x.appendChild(y)
makes y
a child of x
in the DOM hierarchy.
We can't really advise what the exact right sequence of appending is because we don't know what HTML structure you're trying to end up with. If you show us what you want the DOM hierarchy to look like when you're done, we can help with the proper code to achieve that.
Post a Comment for "Dynamic Creating Elements Using Javascript"