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 7 of 7
  1. #1
    Registered User
    Join Date
    Jan 2004
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    onmouseover to change bg

    I'm trying to use an onmouseover to change the background of one of my <div> statements, but it doesn't seem to work. Here's my line of code:

    <div id="button1" style="background-color: #7f25a7; position: absolute; width: 44px; height: 41px; top: 331 px; left: 80px;">
    <table width="100%" height="100%">
    <tr>
    <td align="center"> <font color="#000000" size="2"><strong><a href="film.asp" onMouseOver="document.getElementById('button1').style.background-color = '#C338FF'">Film</a></strong></font>
    </td>
    </tr>
    </table>
    </div>

    thanks,
    jga

  • #2
    Senior Coder coothead's Avatar
    Join Date
    Jan 2004
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,745
    Thanks
    0
    Thanked 244 Times in 239 Posts
    Hi there jgallen,

    When using javascript you have to change the
    css attributes in this manner....

    background-color becomes backgroundColor
    border-color becomes borderColor
    font-size becomes fontSize

    etc

    cthead

  • #3
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    Unless of course you use cssText but I'm not sure how crossbrowser that is.

    *moving to javascript*
    Omnis mico antequam dominus Spookster!

  • #4
    Regular Coder trib4lmaniac's Avatar
    Join Date
    Feb 2004
    Location
    Cornwall, UK
    Posts
    535
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The problem with changing the background like that is that IE and NS handle the style attribute differently. In NS if you want to access an objects style properties its written document.getElementById('button1').backgroundColor however in IE you access it similiar to how you've written it document.getElementById('button1').style.backgroundColor

  • #5
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Well, that was nn4. In Mozilla or browsers based on it (ns6+, Mozilla Firebird, Camino, Galeon, K-Melon etc.), in Opera 7 or in khtml based browsers such as Apple Safari, OmniWeb or Konqueror you use the style property to set styles. In iem and iew you do it that way as well.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #6
    Registered User
    Join Date
    Jan 2004
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    netscape doesn't use position:absolute does it? because I looked at the page in netscape and it looks pretty messed up

  • #7
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    What browser do you mean by "netscape"? Nn4? Ns6? Ns7? Moz?
    They all support absolute positioning, but nn4 is quirkier than any other browser.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards


  •  

    Posting Permissions

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