HTML, JavaScript, Web, Wordpress

Need A Quick CSS Override On Just One Page Via JavaScript?

Found this to work really well for a WordPress custom theme where the only option I had was to drop an override via a header/footer plugin option:

<script>
var ref= window.location.pathname;
var search="/youruniquepagelink/";
if (ref.indexOf(search) > -1) {
let myElements = document.querySelectorAll(".your-class");
for (let i = 0; i < myElements.length; i++) {
	myElements[i].style.display = "none";
}
}
</script>

Questions? Comments?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s