I have this thing on my webpage… I guess it could be called a widget…
How do I separate it’s CSS and JS from the containing page’s CSS and JS? preferably without using an iframe?
In my app the user can customize the CSS of the content, so, I’d need a clean slate.
On the outermost element of your widget, set a relatively unique class name. For example:
Put the Javascript and CSS in their own files. For the CSS, structure all of your selectors like this:
That ensures your rules do not accidentally get overridden by other CSS rules.
Likewise with the JavaScript, prefix your functions with a common, distinctive prefix:
Avoid global variables if possible, but if you cannot, prefix them as well: