onMouseOver to change/hide text

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • CQMMAN

    #1

    onMouseOver to change/hide text

    Hello,

    I am trying to change a piece of text using onmouseover. I have tried a few
    things so far and nothing has really worked. I get get a new piece of text
    to appear but bastardizing someone elses code, but can't figure out how to
    hide the other one....

    I sort of have the following but don't know if this is close to the best way
    of doing it really...

    Basically I want to have a piece of text, lets say TEXT1, that changes from
    blue to red, and to TEXT2 while the mouse is over it.

    I know nothing really about Java so have had a look around but got no
    futher. Any help would be great.

    Cheers




    <html>
    <head>
    <script type="text/JavaScript">
    function setText(t){
    if(document.lay ers)
    {
    with(document.l ayers["myDiv"].document)
    {
    open();
    write(t);
    close();
    }
    }
    else if(document.all )
    {
    myDiv.innerHTML = t;
    }
    }
    </script>
    </head>
    <body>
    <a href="#"
    onmouseover="se tText('test2)",
    onmouseout="set Text('')">test1 </a>&nbsp;


    &nbsp;<br>
    <div style="position :absolute;top:1 4;left:11;width :100;" name="myDiv"
    id="myDiv"></div>
    </body>
    </html>




  • SanJoseWebGuy

    #2
    Re: onMouseOver to change/hide text

    You might try this too:
    <p onMouseOver="th is.style.color= '#FF0000', this.innerHTML= 'The Text
    Changed' "
    onMouseOut ="this.style.co lor='#000000', this.innerHTML= 'Change My
    Color' "[color=blue]
    >[/color]
    Change My Color
    </p>

    Comment

    • CQMMAN

      #3
      Re: onMouseOver to change/hide text


      "SanJoseWeb Guy" <sanjosewebguy@ aol.com.nospam> wrote in message
      news:2003112909 4133.27917.0000 1252@mb-m06.aol.com...[color=blue]
      > You might try this too:
      > <p onMouseOver="th is.style.color= '#FF0000', this.innerHTML= 'The Text
      > Changed' "
      > onMouseOut ="this.style.co lor='#000000', this.innerHTML= 'Change[/color]
      My[color=blue]
      > Color' "[color=green]
      > >[/color]
      > Change My Color
      > </p>
      >[/color]

      Thanks for the tip. Sorry, thought I can't get it to work.. What else do I
      need with your snippet? I really don't know javascript at all..

      Cheers


      Comment

      • CQMMAN

        #4
        Re: onMouseOver to change/hide text


        "SanJoseWeb Guy" <sanjosewebguy@ aol.com.nospam> wrote in message
        news:2003112909 4133.27917.0000 1252@mb-m06.aol.com...[color=blue]
        > You might try this too:
        > <p onMouseOver="th is.style.color= '#FF0000', this.innerHTML= 'The Text
        > Changed' "
        > onMouseOut ="this.style.co lor='#000000', this.innerHTML= 'Change[/color]
        My[color=blue]
        > Color' "[color=green]
        > >[/color]
        > Change My Color
        > </p>
        >[/color]


        Sorry to be such a pain, but that looks like it should do what I want, but
        when I paste it into a n HTML document, it displays "Change My Color", but
        doesn't actually do anything.

        Do I need to define style or colour, or innerHTML somewhere?

        Thanks


        Comment

        • Lasse Reichstein Nielsen

          #5
          Re: onMouseOver to change/hide text

          "CQMMAN" <cqmman@yahoo.c o.uk> writes:
          [color=blue]
          > "SanJoseWeb Guy" <sanjosewebguy@ aol.com.nospam> wrote in message
          > news:2003112909 4133.27917.0000 1252@mb-m06.aol.com...[/color]
          [color=blue][color=green]
          >> <p onMouseOver="th is.style.color= '#FF0000', this.innerHTML= 'The Text
          >> Changed' "[/color][/color]

          I would change the "," to a ";". While legal, commas are used to
          separate expressions (and evaluates to the last expression) while
          semicolons are used to to end statements. In the above, the value of
          the second (assignment-)expression is not relevant, so it's more
          appropriate to treat it as a statement.
          [color=blue]
          > Sorry to be such a pain, but that looks like it should do what I want, but
          > when I paste it into a n HTML document, it displays "Change My Color", but
          > doesn't actually do anything.[/color]

          Does it give a Javascript error message? Have you turned Javascript error
          messages on? (If not, do so!)

          I can see your quote has line breaks all over the place. You can not
          have line breaks inside Javascript strings, so try putting more of it on
          one line.

          It works for me if I do.
          [color=blue]
          > Do I need to define style or colour, or innerHTML somewhere?[/color]

          No, they already exist on the element.

          /L
          --
          Lasse Reichstein Nielsen - lrn@hotpop.com
          DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
          'Faith without judgement merely degrades the spirit divine.'

          Comment

          • CQMMAN

            #6
            Re: onMouseOver to change/hide text


            "Lasse Reichstein Nielsen" <lrn@hotpop.com > wrote in message
            news:wu9hiw2z.f sf@hotpop.com.. .
            [color=blue]
            > Does it give a Javascript error message? Have you turned Javascript error
            > messages on? (If not, do so!)
            >
            > I can see your quote has line breaks all over the place. You can not
            > have line breaks inside Javascript strings, so try putting more of it on
            > one line.
            >
            > It works for me if I do.[/color]

            Aaahhh.. Yes, linewrap.... Thanks very much for your help..

            Cheers
            CQMMAN


            Comment

            Working...