Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Sep 2011
    Posts
    274
    Thanks
    38
    Thanked 0 Times in 0 Posts

    Changing colour on click

    How come this isn't working?

    document.getElementById('glance').style.display='block'.color='gold';

  • #2
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    ...because that is technically erroneous. You should use:
    Code:
    document.getElementById('glance').style.display='block';
    document.getElementById('glance').style.color='gold';
    ...or a less verbose:
    Code:
    document.getElementById('glance').setAttribute('style','display:block;color:gold');
    Hope that helps.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • Users who have thanked rangana for this post:

    FlashDance (10-03-2011)

  • #3
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    You should better create a separate CSS class and change rather the class name than each property line by line.
    Code:
    element.onclick=function(){this.className='newClass'}
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #4
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,296
    Thanks
    13
    Thanked 345 Times in 341 Posts
    Quote Originally Posted by rangana View Post
    ...or a less verbose:
    Code:
    document.getElementById('glance').setAttribute('style','display:block;color:gold');
    … or
    Code:
    document.getElementById('glance').style.cssText = "display:block; color:gold";
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •