how to overwrite css height set by jquery/javascript?

别说谁变了你拦得住时间么 提交于 2019-12-05 01:52:51

setHeight, not $setHeight. and the !important is unneeded.

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.

$("#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:

$("#someElement").height(setHeight);

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');

Take out dollar sign ;) 'setHeight'

That should totally work except that your variable is setHeight and you are trying to use $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. The style tag should overwrite any .css definition unless you have !important in it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!