Page 1 of 1

Alter CSS value

Posted: Mon Jan 10, 2011 6:48 pm
by TonsOfFun
This seems like a very simple problem but I can't for the life of me figure it out.

So I have a site that if JavaScript isn't enabled, the cursor on the <a> is default.
If JavaScript is enabled then the <a> cursor is pointer.

My CSS is:

Code: Select all

#port a {cursor:default;}
and the JavaScript is:

Code: Select all

<script type="text/javascript">
document.getElementById(port).style.a.cursor = "pointer";
</script>
The <a> is in an unordered list in a div with an id or port.

Thanks for any help.

Re: Alter CSS value

Posted: Mon Jan 10, 2011 6:57 pm
by josh
? ok. Thanks for what help though?

Re: Alter CSS value

Posted: Mon Jan 10, 2011 7:08 pm
by TonsOfFun
josh wrote:? ok. Thanks for what help though?
help figuring out why it's not working?

Re: Alter CSS value

Posted: Mon Jan 10, 2011 8:35 pm
by josh
getElementById(port) should be getElementById('port')
(quotes are needed).

Download firebug, a firefox extension. It will show you these errors.

also getElementById will not work in all browsers. If you want maximum compatibility across browsers, with the last amount of code, I'd look into a javascript framework such as jquery. Its still "regular" javascript code you're just using other people's time saving functions.

$('.port').css('cursor', 'pointer');

That would be the jquery code to set the cursor:pointer for all objects on the page with a class of "port". It would be cross browser compatible. Its also worth mentioning your example could be written more efficiently with CSS (no javascript), but I'll assume it was just an example.