Jump to content

A JavaScript beggine question


primefalcon

Recommended Posts

I pretty adept these days at php, and decided to start delving into the client side scripting as php alone doesn't do everything I want such as pulling data from databases without reloading screen, automatically refreshing that data at say 1 second intervals without reloading the page and more, for use on chat rooms and more.I've been starting to try and study JavaScript today its seems simpler than I thought with a syntax very close to php using and if else and such as well.anyhow I have a script specific question for my learnings

  • In a specific script iI was writing it had this line of code
    <a href="java script:;" onclick="document.bgColor='#E3701A'">Testing 1,2 and 3</a>

    now that is largely my own modification of their example to find out how it works but I've tried to use an rgb value in there like this

    <a href="java script:;" onclick="document.bgColor='rgb(55, 55, 55)'">

    and I cant get it to work, is there a way to use rgb values in this style or am I trying to do something impossible?

Thank you in advance for any help :-)

Link to comment
Share on other sites

bgColor isn't a standard attribute, it's not CSS. That's why you can't use rgb values.Try this:<a href="javascript:void(0);" onclick="document.body.style.backgroundColor='rgb(55, 55, 55)'">

Link to comment
Share on other sites

Ok that works great, thank you though you have script color changes using that seems to stop the standard bg.color from working, which is honestly no big deal, since I can just convert it all over to rgb which easier to work with anyhow.Thank you

Link to comment
Share on other sites

Try to use CSS instead of presentation attributes.
Like this?onclick="document.body.className='otherClass'"I agree in principle, but, well . . .Or did you have something better in mind? I am but a grasshopper.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...