tags:

views:

26

answers:

2

I have this code that works as posted:

$('#cs_tableVideoListings tbody tr td').each(
    function() {
        $(this).css('border-bottom','2px solid gray');
    })

the issue is that "gray" is too dark. When I try #333 or any hex number, it doesn't work at all.

I only need to apply the bottom border, so using "border-bottom" : "2px solid #333" (note colon) doesn't work as that syntax seems to only work when applying multiple styles.

So, I'm wondering at to apply a hex color in the above code w/o getting ridiculous about assigning variables and such.

Thanks

A: 

Hi,

Try to long hand version #333333 instead of the short hand #333. I remember having trouble with the short hand CSS hex colors.

Or you could change your code to something like this:

$(this).css({
    borderBottomWidth: '2px',
    borderBottomStyle: 'solid',
    borderBottomColor: '#333333'
});

Note that the object keys that I passed is borderBottom (JS) instead of border-bottom (CSS). When you pass in an object to jQuery.css it should be the JavaScript equivalent of the style.

http://codepunk.hardwar.org.uk/css2js.htm

Sandro
+1  A: 

Your code is fine until you decided to add the colon.

You don't want the colon in there unless you're passing an object. The number format #333 works fine either way.

Try it out: http://jsfiddle.net/EXbL7/

$('#cs_tableVideoListings tbody tr td').each(
    function() {
              // separated with comma, you're passing 2 arguments
        $(this).css('border-bottom','2px solid #333');
    }
);

If you do want the colon, then you need to pass an object.

Try it out: http://jsfiddle.net/EXbL7/1/

$('#cs_tableVideoListings tbody tr td').each(
    function() {
              // separated with colon, you're passing 1 object argument
        $(this).css( {'border-bottom':'2px solid #333'} );
    }
);
patrick dw
Hi, I just tried this out and both your example and my example don't seem to work. Try changing the color to #330000, should be red, but I still get black. Type in red instead and you see red.
Sandro
@Sandro - Both examples work fine for me. http://jsfiddle.net/EXbL7/2/ and http://jsfiddle.net/EXbL7/3/ What browser are you using?
patrick dw
I'm using Safari on a Mac. Tried it on Chrome and Firefox and it didn't work either. Weird, right? Maybe it's a Mac thing?
Sandro
@Sandro - I'm using Safari on Mac as well. Did you click the links in my comment above? These are standard CSS values and work cross-browser.
patrick dw
This works for me on the three browsers also:$(this).css( {'border-bottom':'2px solid rgb(0,0,255)'}
Sandro
Yea, clicked on your jsfiddle.net link. I updated the hex value to #330000 and the color is just black. But if I use 'red' or rgb(255,0,0) the color is red. It's really weird. Using Safari 4.0.5 (I should probably update it).
Sandro
That's so embarrassing. Sorry for the confusion. You're right #ff0000 is red. And it works. Sorry again.
Sandro
@Sandro - That's alright. I deleted my comment above, because I tested your color, and saw black too. But then I realized that it was just so dark that it was barely distinguishable from black.
patrick dw
Yikes. After doing all this since 1996, I still make mistakes... I was thinking #ddd but writing #333... it works fine. Sorry for this posting but I guess that's what virtual eyes/minds are for!
Billy
@Billy - Not a problem. :o) Just remember to click the checkmark to the left of this answer if it was helpful.
patrick dw