Hi guys....
I am having trouble changing the color of the LEFT border in a table.

i'm using the following javascript:

document.getElementById("cell1").style.border-left="3px red solid";

cell1 is the correct id of the table cell.
If i take away the "-left" part in "border-left", it will change the border of the whole cell. Problem is, i need to change only SPECIFIC borders.

Any Suggestions?

Rock On

Recommended Answers

All 4 Replies

Try "borderLeft" instead. One of the unfortunate aspects of web development is that the CSS property may or may not have a corresponding JavaScript property, and they don't always map directly to each other. Also, as you can see, the spelling will differ.

So, "style.borderLeft" is the JavaScript property that changes the "border-left" CSS declaration.

Here's a nice cross-reference: http://codepunk.hardwar.org.uk/css2js.htm

commented: Huge help! provided great reference as well +1

Javascript doesn't use the hyphens that are present in CSS.

As a general rule, if the CSS style is border-left, margin-top, etc, the javascript equivalent will be borderLeft, marginTop, etc.

What do the call that...camel code? Something like that.

camelCase ;)

That's it!

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.