Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Javascript Help

  1. #1
    Join Date
    Nov 2007
    Location
    London
    Posts
    1,577
    Tokens
    36

    Latest Awards:

    Default Javascript Help

    I'll try and make this has informative and brief as possible...

    I have links (<a href="#">) and I need it so that when the click is clicked (onClick="") it changes a CSS 'element''s value. So, when click, it changes the "background" of the div with the ID "banner". So in the CSS document I have:

    Code:
    #banner {
        background: url(images/banner.png);
        more css blah
    }
    Onclick of this particular link, I need it to dynamically become:

    Code:
    #banner {
        background: url(images/banner2.png);
        more css blah
    }
    Any help will be appreciated, thanks.
    Kind Regards,

    Guy
    __________________

    Since 2007. Unbelievable Uptime. Web hosting, resellers, master resellers, linux VPS, windows VPS, shoutcasts, at the lowest prices on the net.
    Tech-Hosts.co.uk.


  2. #2
    Join Date
    Feb 2006
    Location
    Scotland
    Posts
    2,087
    Tokens
    138

    Latest Awards:

    Default

    http://www.codingforums.com/showpost...51&postcount=2

    Quick Google brought that up, should work.

  3. #3
    Join Date
    Nov 2007
    Location
    London
    Posts
    1,577
    Tokens
    36

    Latest Awards:

    Default

    Quote Originally Posted by Johno! View Post
    http://www.codingforums.com/showpost...51&postcount=2

    Quick Google brought that up, should work.
    Thanks, but I've already tried that and couldn't get it to work.

    Maybe I'm just being an idiot, but if it works I usually manage to get it to work, and I couldn't?

    If a javascript coder can use the guide there (http://www.codingforums.com/showthread.php?t=122011) and get it to work in the way I need it, please let me know how you did it.

    Or... any other suggestions?

    Thanks very much.
    Kind Regards,

    Guy
    __________________

    Since 2007. Unbelievable Uptime. Web hosting, resellers, master resellers, linux VPS, windows VPS, shoutcasts, at the lowest prices on the net.
    Tech-Hosts.co.uk.


  4. #4
    Join Date
    Feb 2006
    Location
    Scotland
    Posts
    2,087
    Tokens
    138

    Latest Awards:

    Default

    Worked for me? Hope you can get it working

    HTML Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
        <head>
            <title>oh hay</title>
            
        <style type="text/css">
        .banner1 {
        background-color: aqua;
        width: 100px;
        height: 100px;
        }
        .banner2 {
        background-color: fuchsia;
        width: 100px;
        height: 100px;
        }
        </style>
        </head>
        
        <body>
        <div id="hello" class="banner1"></div>
        <a href="#hello" onclick="document.getElementById('hello').className ='banner2'">Hello</a>
        </body>
    </html>
    Last edited by Johno; 14-07-2009 at 01:25 AM.

  5. #5
    Join Date
    Oct 2005
    Location
    Melbourne, Australia
    Posts
    7,554
    Tokens
    0

    Latest Awards:

    Default

    Try this:

    HTML Code:
    <a href="#" onclick="document.getElementById('banner').style.backgroundImage='url(background2.jpg)';">click.</a>

  6. #6
    Join Date
    Apr 2009
    Location
    United Kingdom
    Posts
    1,111
    Tokens
    100

    Latest Awards:


  7. #7
    Join Date
    Nov 2007
    Location
    London
    Posts
    1,577
    Tokens
    36

    Latest Awards:

    Default

    Quote Originally Posted by Johno! View Post
    Worked for me? Hope you can get it working

    HTML Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
        <head>
            <title>oh hay</title>
            
        <style type="text/css">
        .banner1 {
        background-color: aqua;
        width: 100px;
        height: 100px;
        }
        .banner2 {
        background-color: fuchsia;
        width: 100px;
        height: 100px;
        }
        </style>
        </head>
        
        <body>
        <div id="hello" class="banner1"></div>
        <a href="#hello" onclick="document.getElementById('hello').className ='banner2'">Hello</a>
        </body>
    </html>
    Got that working now, thanks very much +rep. It doesn't look as good as I wanted, so I'm going to try and work out how to add a fade to the changeover now haha.

    Any suggestions or help on ths would also be appreciated.
    Kind Regards,

    Guy
    __________________

    Since 2007. Unbelievable Uptime. Web hosting, resellers, master resellers, linux VPS, windows VPS, shoutcasts, at the lowest prices on the net.
    Tech-Hosts.co.uk.


  8. #8
    Join Date
    Apr 2009
    Location
    United Kingdom
    Posts
    1,111
    Tokens
    100

    Latest Awards:

    Default

    Quote Originally Posted by iUnknown View Post
    Got that working now, thanks very much +rep. It doesn't look as good as I wanted, so I'm going to try and work out how to add a fade to the changeover now haha.

    Any suggestions or help on ths would also be appreciated.
    Use jQuery. You can do like css change then .fade('slow'); or whatever.


  9. #9
    Join Date
    Nov 2007
    Location
    London
    Posts
    1,577
    Tokens
    36

    Latest Awards:

    Default

    Quote Originally Posted by BoyBetterKnow View Post
    Use jQuery. You can do like css change then .fade('slow'); or whatever.

    I've got jquery now but I'm awful at javascript... I need a little bit more detailed advice on how to use it Can I use jquery to add a fade to something like this?

    Code:
    onclick="document.getElementById('banner').className ='banner2'"
    Kind Regards,

    Guy
    __________________

    Since 2007. Unbelievable Uptime. Web hosting, resellers, master resellers, linux VPS, windows VPS, shoutcasts, at the lowest prices on the net.
    Tech-Hosts.co.uk.


  10. #10
    Join Date
    Nov 2007
    Location
    London
    Posts
    1,577
    Tokens
    36

    Latest Awards:

    Default

    Can't edit, please merge my posts.

    This is now my code:

    Code:
    function imgChange1() {
    document.getElementById('banner').className ='banner1';
    }
    
    function imgChange2() {
    document.getElementById('banner').className ='banner2';
    }
    
    function imgChange3() {
    document.getElementById('banner').className ='banner3';
    }
    
    function imgChange4() {
    document.getElementById('banner').className ='banner4';
    }
    
    function imgChange5() {
    document.getElementById('banner').className ='banner5';
    }
    What can I add to the functions to make it do that with a fade?

    Thanks.
    Kind Regards,

    Guy
    __________________

    Since 2007. Unbelievable Uptime. Web hosting, resellers, master resellers, linux VPS, windows VPS, shoutcasts, at the lowest prices on the net.
    Tech-Hosts.co.uk.


Page 1 of 2 12 LastLast

Posting Permissions

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