user image

Jo Micheal
Published in : 2022-01-27

How to use !important using jQuery css function?


Hello everyone, I am facing an issue when I try to use CSS function using jQuery to set !important the code I am using is 

jQuery("div.shipping_address").css({ "display": 'none !important' });

it adds the display: none; but without the !important What should I do to add it?

Thanks in Advance


Joseph Morgan Date : 2022-01-27

Best answers


Best answers


Welcome Back Jo,
Css function in jQuery doesn't support !important so the other way to do this is by adding using .attr like this code below 

jQuery("div.shipping_address").attr("style", "display: none !important;");

this gonna work with you also you can keep main style of the div by storing the attribute value in element then add it to the code above like 

var styleAttr = jQuery("div.shipping_address").attr('style');jQuery("div.shipping_address").attr("style", styleAttr+"display: none !important;");

Good luck

Jo Micheal Date : 2022-01-27

Thank you this is really helpful

Leave a comment

Join us

Join our community and get the chance to solve your code issues & share your opinion with us

Sign up Now

Related posts

jQuery Selector is not working .click
Publish date: 2022-02-21 | Comments: 1

Tag: jQuery

How to get the style of element in jQuery? add it to another
Publish date: 2022-01-27 | Comments: 2

Tag: jQuery

Display JSON in HTML using jQuery
Publish date: 2022-01-30 | Comments: 2

Tag: jQuery

Accessing Radio button values using Jquery
Publish date: 2022-03-05 | Comments: 1

Tag: jQuery

jQuery alter the class of a button when I click on it?
Publish date: 2022-02-12 | Comments: 1

Tag: jQuery

[solved] SyntaxError: Unexpected token o in JSON at position 1 jQuery
Publish date: 2022-01-30 | Comments: 2

Tag: jQuery

[SOLVED] jQuery .click() not working with auto added buttons
Publish date: 2021-06-19 | Comments: 2

Tag: jQuery