[英]how to overwrite css height set by jquery/javascript?
I have this:我有这个:
var setHeight = $(this).outerHeight();
// returns e.g. 687
$("#someElement").css({'height': $setHeight+"px !important" });
// I want to override this jquery-set height
I'm not sure this is the right way... probably not, since it's not working.我不确定这是正确的方法……可能不是,因为它不起作用。
Thanks for helping out!感谢您的帮助!
Your variable name doesn't have a leading $
.您的变量名称没有前导
$
。 Also, the !important
flag will cause this not to work in Firefox, however as you're applying this style directly to the element, you shouldn't need it.此外,
!important
标志将导致这在 Firefox 中不起作用,但是当您将此样式直接应用于元素时,您不应该需要它。
$("#someElement").css('height', setHeight + "px");
Also note that if you're only setting the element's height you can also just shorten this to a height()
call:另请注意,如果您只设置元素的高度,您也可以将其缩短为
height()
调用:
$("#someElement").height(setHeight);
setHeight
, not $setHeight
. setHeight
,而不是$setHeight
。 and the !important
is unneeded.并且
!important
是不需要的。
Your variables don't match;您的变量不匹配; remember that punctuation and proper spelling are important to calling the variable properly;
请记住,标点符号和正确拼写对于正确调用变量很重要; try changing the second line to:
尝试将第二行更改为:
$("#someElement").css('height',setHeight+'px !important');
取出美元符号 ;) 'setHeight'
That should totally work except that your variable is setHeight
and you are trying to use $setHeight
.这应该完全有效,除了您的变量是
setHeight
并且您正在尝试使用$setHeight
。 Make sure they are the same.确保它们相同。 Make sure your selector is correct and obtaining the element.
确保您的选择器正确并获取元素。 I believe that you don't even need the
!important
.我相信你甚至不需要
!important
。 The style tag should overwrite any .css definition unless you have !important
in it. style 标签应该覆盖任何 .css 定义,除非你有
!important
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.