Onmouseover help please

Discussion in 'JavaScript' started by blade001, Jul 25, 2012.

  1. #1
    I don't know much about javascript but i am trying to add an image. I did not create the site but i am trying to edit it at my work.


    My question is i know the onmouseover code is wrong, what is the right code?

    Ignore it not being closed but when i try and replace the image it doesn't work, ive tried to look up different ways on the net but no luck.
    pay close attention to the ON MOUSE OVER part. thanks
     
    Solved! View solution.
    Last edited: Jul 25, 2012
    blade001, Jul 25, 2012 IP
  2. #2
    Try changing this
    
    <img name="imgAbout" src="images/ban2.jpg" border="0" />
    
    Code (markup):
    to this
    
    <img id="imgAbout" src="images/ban2.jpg" border="0" />
    
    Code (markup):
    And then use replace all "document.imgAbout" with "document.getElementById('imgAbout')"
     
    Unni krishnan, Jul 25, 2012 IP
    blade001 likes this.
  3. blade001

    blade001 Member

    Messages:
    168
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #3
    Thank you very much, worked fine :cool:
     
    blade001, Jul 25, 2012 IP
  4. Unni krishnan

    Unni krishnan Peon

    Messages:
    237
    Likes Received:
    9
    Best Answers:
    2
    Trophy Points:
    0
    #4
    Happy that it helped and thanks for the rep.
     
    Unni krishnan, Jul 26, 2012 IP
  5. Sitesupplier

    Sitesupplier Peon

    Messages:
    16
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    0
    #5
    Is that in-line JavaScript I see? That's disgusting! Separate your code and use external JavaScript or at least keep your JavaScript code in its own tags. Using this:
    <input type="text" id="testing" onmouseover="" />
    Code (markup):
    ... is archaic! Instead, use this:
    <script type="text/javascript">
    
    document.getElementById("testing").addEventListener("mouseover", some_function, false);
    
    function some_function()
    {
        // Do something
    }
    
    </script>
    
    <input type="text" id="testing" />
    Code (markup):
    I know it looks like more work to begin with, but you can make this function generic and have it work with all your HTML <li> elements by virtue of the JavaScript target.id/srcElement.id (standards-compliant, MSIE, respectively).
     
    Sitesupplier, Jul 30, 2012 IP
    blade001 likes this.
  6. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #6
    While to me, it looks like you're using javascript to do CSS' job, but I'd have to actually see what it is you're even trying to do on a page, or at very least the CSS already being applied to say for sure how to go about that.

    Also, much of that doesn't look like a job for lists... or at least not multiple lists.

    Since you're using the same images on all of them though, that really should probably be a image declared in the CSS on a sandbag type span that you apo over the the sibling image -- assuming that said IMG should even be there in the first place given that none of it looks like it's content.

    I mean, you're just changing style on hover, this isn't 1998... you don't need scripting for that.
     
    deathshadow, Aug 2, 2012 IP
    blade001 likes this.
  7. blade001

    blade001 Member

    Messages:
    168
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #7

    Thanks for your input. I actually did not write the code, im very new to coding and only really know xhtml. I was just helping "adjust" the site at work.
    The code was written by a guy who is friends with my boss.
     
    blade001, Aug 17, 2012 IP
  8. blade001

    blade001 Member

    Messages:
    168
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #8
    Thanks for your input. I actually did not write the code, im very new to coding and only really know xhtml. I was just helping "adjust" the site at work.
    The code was written by a guy who is friends with my boss.
    I'm actually 21 and so I wouldn't know about coding in 1998 :)
     
    blade001, Aug 17, 2012 IP
  9. blade001

    blade001 Member

    Messages:
    168
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #9
    thread can be closed
     
    blade001, Aug 17, 2012 IP