Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Help with making a rollover object with Javascript?

I am trying to make a block of text in a <p> tag to appear upon rollover of another <img>. I have been trying to do it with the code looking like:

<a onmouseover="document.name.style.visibility='visible'"><img /> </a>

<p name="name">

The problem is that the <p> tag cannot have a "name" attribute. Therefore, I am not sure how to code the javascript and html in order to make it so that when you roll over the <img>, the <p> will show up.

1 Answer

Relevance
  • 1 decade ago
    Favorite Answer

    The "name" attribute is becoming depreciated. Try using the "ID" attribute instead. Here is how you would do it using this method:

    <img src="your-image.jpg" onmouseover = "document. getElementById ('my-appearing-paragraph'). style. visibility = 'block';" />

    <p id="my-appearing-paragraph" style="visibility:none;">

    Here is the content that is initially invisible.

    </p>

    Also, if you want the paragraph to be hidden again afterward, make sure to include onmouseout = "document. getElementById ('my-appearing-paragraph'). style. visibility='none';". Good Luck!

    (I had to edit this post because it cut off my code and put in "..." I added spaces into the code - around the equal sign and after all of the periods, and before the parenthesis. It won't work with the spaces after the periods and before the parenthesis, but you can figure it out :)

    Source(s): I am a programmer.
Still have questions? Get your answers by asking now.