Reputation: 9622
I am working in a large java script code base affected by multiple different companies. Within the thousands of lines of code I have a small section I am allowed to modify (and only that section) where a button is added.
I need to change the color of the button and make sure that no amount of foreign CSS or html formatting changes it further.
So something like button.style.backgroundColor = "color";
button.style = "style can only be changed through javascript";
Upvotes: 1
Views: 50
Reputation: 8670
As always you can use "!important" on all your property values.
If you're unfamiliar "!important" will prevent the typical cascade effect from occurring and preserve the important value:
button {
color: red !important;
}
button {
color: green;
}
<button>Example</button>
It's important to realize that if further down the cascade another !important value is declared, the cascade will take effect.
button {
color: red !important;
}
button {
color: green !important;
}
<button>Example</button>
but the best way to prevent tampering would be to give it a class name that would be entirely unique and to define all the relevant properties within it.
Outside of these things, you have to understand that web development is supposed to be malleable, so there's no way just to lock-down your element and prevent tampering from traditional sources.
Upvotes: 1