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 ;)

Recommended Answers

All 2 Replies

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...

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.