Table of Contents
- Utilizing the innerHTML characteristic
- Utilizing the insertAdjacentHTML() strategy
Utilizing the innerHTML characteristic:
To annex utilizing the innerHTML trait, first select the component (div) where you need to affix the code. Then, at that point, add the code encased as strings utilizing the += administrator on innerHTML.
element.innerHTML += "additional HTML code"
element.innerHTML = element.innerHTML + "additional HTML code"
Note: This strategy fundamentally annihilates all the substance of the div and reproduces it. Along these lines, assuming you have any audience members joined to the youngster hubs of that div, they will be lost.
Utilizing the insertAdjacentHTML() technique
HTML code can be attached to a div utilizing the insertAdjacentHTML() strategy. Be that as it may, you really want to choose a component inside the div to add the code. This strategy takes two boundaries:
The situation (in the record) where you need to embed the code (‘afterbegin’, ‘beforebegin’, ‘afterend’, ‘beforeend’)
The HTML code you need to embed encased in statements
elementInsideDiv.insertAdjacentHTML('afterend', 'additional HTML code');
Note: You ought to never embed the HTML code along these lines assuming you are accepting it as a contribution from the client. It opens your site to cross-site prearranging weaknesses.
Also Read: Returning Multiple values in Java