Почему не срабатывает такой jQuery код?

Рейтинг: -1Ответов: 1Опубликовано: 07.10.2014

Почему не срабатывает такой jQuery код?

jQuery(document).ready(function($){
      if (window.location.pathname == '/lechenie-narkomanii.html') {
        $(".contentwidthr").css("width","100% !important");
      };
      if (window.location.pathname == '/vazhno-znat.html') {
        $(".contentwidthr").css("width","100% !important");
      };
    });

В чем проблема? CSS значение не заменяется...

Ответы

▲ 1

По-моему, js вставить "!important" не может.

https://stackoverflow.com/questions/5824079/using-important-in-jquerys-css-function https://stackoverflow.com/questions/11733844/how-to-add-important-to-a-stylesheet-rule-using-javascript

Прогуглите про свойство style.cssText или попробуйте добавить класс к элементу. Например, так:

<style>
  .qwerty { 
    width: 100% !important;
  }
</style>
...
<script>
if (location.pathname == "/lechenie-narkomanii.html") {
  $(".contentwidthr").addClass("qwerty");
}
</script>