How to override css containing '!important' using jquery?

前端 未结 15 698
清歌不尽
清歌不尽 2020-12-29 21:05

I want to apply height for specific div using jquery but not able to override the \'!important\' keyword using jquery.

Here is

15条回答
  •  我在风中等你
    2020-12-29 21:21

    I prefer to create a class and add it to specific div, for example

    This can be either inline or in an external CSS file:

    
    

    If this is something that is never going to change, you can manually add the class to that div:

    sometext here

    or you can use jQuery to add this script tag at the bottom of that page

    
    

    You can use the 'style' option, but would recommend doing it this way:

     var currentStyle = $('#divL3').attr('style');
     $('#divL3').attr('style', currentStyle + ' width:500px !important;');
    

    This way you do not override the existing style, in case a third party plugin adds any dynamic style to your page, which is not unusual if you are using a CMS like WordPress.

提交回复
热议问题