0

okay, I've got another problem.
How can I obtain content of cascade style, using javascript?
I know, there's a code

document.getElementById('id').style.border='5px solid blue';

for example, but I need to do reversed operation, not to change style, but obtain it.
I hope I've described my problem clearly enough enough ;)
Thanks for any help ;)

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by extemer
0

Hi Willy

The style object can be used to not only set but get information too. So to reverse your statement, try:

var myBorder = document.getElementById('id').style.border;

The string returned by style.border should look much like your example "5px solid blue", with the border's width, style, and color in a single line.

It's often more convenient to access each attribute individually. For border styles you can do so by going through the style.border property like this:

var myColor = document.getElementById('id').style.border.color;
var myStyle = document.getElementById('id').style.border.style;
var myWidth = document.getElementById('id').style.border.width;

The style object also provides properties that map more directly to attributes, such as style.borderWidth or style.borderLeftWidth. There's a certain amount of duplication here, but you'll find the access offered is sometimes more refined.

Further info: HTML DOM Style Object...

Edited by LaxLoafer: n/a

0

i will suggestion you to switch to JQUERY because it better,fast and easy to do what ever you want if want it in JQUERY i can tell you how.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.