-1

Почему не срабатывает такой 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 значение не заменяется...

3
  • 1
    Одного вопроса мало? hashcode.ru/questions/365968/…
    – andreyqin
    7 окт 2014 в 10:42
  • Покажите полный код страницы для полной картины.
    – cema93
    7 окт 2014 в 19:17

1 ответ 1

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>

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.