Grow your CSS skills. Land your dream job.

Change the style of an element using JS

  • # April 16, 2009 at 7:06 am

    Hello!

    I have a question that will probably seem really simple but I don’t really no how to use JavaScript so have no idea…

    What i would like to do would be that when people click inside an input box to start typing, the hole div holding that box changes colour to something set buy me, this is the layout so far…
    ___________styling__________

    .normal
    {
    background-color:gray;
    }.focus
    {
    background-color:white;
    }
    #contactbox1{
    height: 100px;
    }
    ______styling_____________

    _____HTML____________
    <div id="contactbox1" class="normal">
    <input type="text" size="40" class="normal" onfocus="this.className=’focus’" onblur="this.className=’normal’" />
    </div>
    _____HTML___________
    That will change the colour of the input box… but I want to change background colour of the div="contactbox1" Any ideas?
    (Does anybody no a good place to learn lots of JavaScript from scratch… Videos would be good as I’m deferentially a visual learner, that’s why I love the CSS-Tricks videos on itunes!)
    Regards

    # April 16, 2009 at 7:57 am

    Thanks for that! That will defiantly help (I need to learn this to be able to do a lots of things lol)! :-)

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".