Get border width from a div with plain javascript

前端 未结 6 1940
日久生厌
日久生厌 2020-12-30 23:44

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 ha

6条回答
  •  一整个雨季
    2020-12-31 00:47

    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

提交回复
热议问题