使用纯javascript从div获取边框宽度 [英] Get border width from a div with plain javascript

查看:82
本文介绍了使用纯javascript从div获取边框宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将这种风格应用于div

  div#content {
border:1px solid blue blueblue;
}

我希望能够提醒边框的宽度,我有试用这个:

  window.alert(document.getElementById(content).style.borderWidth); 

听说取决于浏览器,也许你可以帮我
我正在使用Firefox 18

解决方案

请尝试以下javascript:

 警报($( #内容)的CSS( 左边框宽度)。); //使用jquery。 

  alert(getComputedStyle(document.getElementById('content'),null).getPropertyValue('border-left-width')); //没有jquery。 

getComputedStyle (元素,伪)

元素:获取样式的元素

pseudo:伪选择器,如'hover';如果不需要,则为null。

参考链接: http:/ /javascript.info/tutorial/styles-and-classes-getcomputedstyle


I got this style applied to a div

div#content {
border: 1px solid skyblue;  
}

and i want to be able to alert the width of the border, I have tried with this:

window.alert( document.getElementById( "content" ).style.borderWidth );

I heard that depends of the browser maybe you can help me I'm using Firefox 18

解决方案

Please try the below javascript:

alert($("#content").css("border-left-width")); //using jquery.

or

alert(getComputedStyle(document.getElementById('content'),null).getPropertyValue('border-left-width'));//without jquery.

getComputedStyle(element, pseudo)

element:The element to get a styling for

pseudo:A pseudo-selector like ‘hover’ or null if not needed.

Reference link: http://javascript.info/tutorial/styles-and-classes-getcomputedstyle

这篇关于使用纯javascript从div获取边框宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆