2016-11-16 2 views
-2

Ниже представлена ​​моя структура HTML. Я хочу, чтобы добавить код CSS в 4 ребенка DIVКод jQuery не работает в Google Chrome

<div class="amazingcarousel-image"> 
    <div></div> 
    <div></div> 
    <div></div> 
    <div></div> 
    </div> 

нормальный код CSS будет, как показано ниже

.amazingcarousel-image div:nth-child(4) { 
    display: none !important; 
} 

Я хочу, чтобы добавить выше CSS с помощью JQuery я добавил код ниже

function tinda() { 
    jQuery(".amazingcarousel-image div:nth-child(4)").css("cssText", "display: none !important;"); 
} 

jQuery(document).ready(function() { 
    tinda(); 
}) 

Проблема заключается в том, что этот код работает в Firefox красиво, но не в Chrome. Пожалуйста, помогите

+0

Он не должен даже работать в FF. 'css (" cssText "," display: none! important; ")' должно быть 'css (" display "," none ")' – j08691

+1

Не выполняйте '.css (" cssText ", ...)'. Используйте его правильно: '.css (" display "," none ")'. –

+1

@MikeC '.css()' не примет '! Important' – j08691

ответ

1
function tinda() { 
    jQuery(".amazingcarousel-image div:nth-child(4)").addClass('hide'); 
} 

.amazingcarousel-image div.hide { 
    display: none !important; 
} 
Смежные вопросы