When adding additional HTML elements to a web page using Javascript / jQuery and adding additional external CSS declarations that you need to use with them, you need to prevent the identifiers of these elements and CSS class names from matching those already on the page. for example, you may already have an ID, for example, "externalWrapper" or "nav" somewhere on the page, and new content may also have identifiers of the same name.
Creating code to be added to your own web pages is relatively simple.
But if you want to provide code that can be used on any third-party website, you cannot control which identifiers and class names are already used on the page, and even less than what changes may be made to the page in the future.
So what is the best practice to prevent these conflicts when working with third-party code?
So far, we just used iframes, but this is not ideal.
The CSS child selector may prevent our added CSS from influencing existing elements / classes, but they will not prevent our new elements from getting CSS styles that were already on the page.
Is the prefix of all the identifiers of our added content, for example, the company, product name or container name, the only way to promote it? for example, the JWPlayer video player prefixes the container name for all element identifiers for its HTML5 player.
I would be grateful for any thoughts.
David source share