There are some rear occasions after working on how things work for a long time on the web. One of these occasions happened last week.
[Read more]
this.domElement is your new document object in SPFx web parts development
You are familiar with the JavaScript method like ‘document.getElementByID’. Since HTML5 the Document Object Model has more to offer than return an element by its ID on a document.
I case of web part development you should forget that the document object inside and HTML exists instead you should request HTML elements differently.
Alternative to innerHTML in SharePoint Framework web parts
When you create a new project without any framework, the default web part content in the code will be added through innerHTML.
Technically there is nothing wrong with this approach, but you might run into a problem when you add more content to the web part afterward using the same method. In this case, the previously added content will be overwritten.
To avoid this behavior, you can use jQuery and the ‘append‘ or ‘prepend‘ methods to add your content. It works well but requires an external library.
Instead of using jQuery, there is a native method in the document object model of HTML available.