Alter CSS value

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
TonsOfFun
Forum Commoner
Posts: 54
Joined: Wed Jun 02, 2010 7:37 pm

Alter CSS value

Post 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.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Alter CSS value

Post by josh »

? ok. Thanks for what help though?
TonsOfFun
Forum Commoner
Posts: 54
Joined: Wed Jun 02, 2010 7:37 pm

Re: Alter CSS value

Post by TonsOfFun »

josh wrote:? ok. Thanks for what help though?
help figuring out why it's not working?
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Alter CSS value

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