Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get border width from a div with plain javascript

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

like image 358
Alejandro Avatar asked Sep 02 '25 09:09

Alejandro


1 Answers

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

like image 147
Sankar V Avatar answered Sep 05 '25 01:09

Sankar V