How to add !important to CSS attribute with jQuery

The !important property is CSS is used to give more importance than normal CSS property. 

In css , !important mean “this is important”. Using !important property means ignore all rule and apply it.

In jQuery, We use css() methods to set or returns style properties to the selected elements.

In this tutorial, I am going to show you how to add !important to CSS property with jQuery.

HTML

<span class="pclu">Phpcluster Programming Blog</span> 

Include jQuery Library

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

jQuery

<script>
$(document).ready(function(){
$(".pclu").css("cssText", "color: red !important;");
});
</script>

Here I have used cssText to set content to rule. 

cssText sets or gets the content of the rules, so you need append it to the existing rule, as it overwrites it.

Leave a Comment