admin管理员组文章数量:1391937
I'm trying to get the max width
of my CSS element by using javascript
.
I'm currently able to get the width but not max-width
.
hsWidth = $("#horizontal-scroll").width();
Thanks
I'm trying to get the max width
of my CSS element by using javascript
.
I'm currently able to get the width but not max-width
.
hsWidth = $("#horizontal-scroll").width();
Thanks
Share Improve this question edited Dec 13, 2016 at 15:56 Sajib Khan 24.2k9 gold badges68 silver badges79 bronze badges asked Dec 13, 2016 at 14:40 MADMAD 211 silver badge3 bronze badges 04 Answers
Reset to default 4Use jQuery method .css()
:
var max_width = $("#horizontal-scroll").css('max-width');
Hope this helps.
var max_width = $("#horizontal-scroll").css('max-width');
console.log(max_width);
#horizontal-scroll{
max-width: 250px;
display: block;
background-color: green;
width: 200px;
height: 50px;
}
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="horizontal-scroll"></div>
You need to use css('max-width')
The following should do it for you
$('#horizontal-scroll').css('max-width');
You can find more information here in the jQuery documentation
Also, please note as per the ment by @low_rents that this will return a string with the measurement unit at the end, for example '100px' or '50%'
You can simply use the '.css()'
method :
$('#horizontal-scroll').css('maxWidth');
Documentation here
Please try this working example
//referencing your example..
var hsWidth = $("#horizontal-scroll").css('max-width');
console.log(hsWidth);
#horizontal-scroll{
height:500px;
width:auto;
max-width:950px;/*we want to get this...*/
}
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!--target element-->
<div id="horizontal-scroll">
</div>
本文标签: jqueryHow to get the max width of my css element using javascriptStack Overflow
版权声明:本文标题:jquery - How to get the max width of my css element using javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744670419a2618789.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论