采取CSS的第一要素
问题描述:
你好,我有一个元素两个CSS样式属性样式中的第一和jQuery的属性CSS中的第二个,我想采取的第一个 这样的:采取CSS的第一要素
$(document).ready(function() {
\t jQuery(".iview-group-19").iView({
\t \t captionSpeed: 500, // speed to show caption
\t \t captionOpacity: 1, // caption opacity
\t \t captionEasing: 'easeInOutSine', // caption transition easing effect, use JQuery Easings effect
\t \t customWidth: 1920,
\t \t customHtmlBullet: false,
\t \t rtl: false,
\t \t height:500,
}); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="iview iview-group-19" id="slide-height" style="height: 351px;">
答
首先,您需要检查元素中是否存在样式元素。如果不存在inline属性。 jQuery的CSS样式将呈现。元素内联总是优先。如果元素中缺少style属性,jquery css会替换该样式。
$(function(){
if(!$("h1").attr("style")){
\t \t $("h1").css({
\t \t \t \t \t "margin":"7px",
\t \t \t \t \t "border":"10px solid red !important",
\t \t \t \t \t "padding":"10px" \t
\t \t });
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1 style="margin:1px;border:1px solid red;padding:10px;" >
Hello test
</h1>
答
尝试这样做:
style="height: 351px !important;"