CALL: 01625 813568

CODE4 DIGITAL

How to use JavaScript to apply CSS

You can try out the below methods to apply styling rules to your HTML elements.

				
					<script>
document.getElementById("yourid").style.color = "green";
</script>

<script>
document.getElementsByClassName('yourclass')[0].style.color = "red";
</script>

<button type="button"
onclick="document.getElementById('yourid').style.color = 'orange'">
Click Me!</button>
				
			

Changing font colour by getElementById: YourID

Changing font colour by getElementByClassName: YourClass

document.getElementById("yourid").style.color = "green"; document.getElementsByClassName('yourclass')[0].style.color = "red";
Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn

Contact Us Today

Web

We can Design & build your website and Social Media Channels.

Marketing

We’ll help you Promote your products and services, track your performance, and make the most out of your marketing spend.

Contact Us

Register your interest in partnering with CODE4 Digital.