12

I have few form fields, each input and label is wrapped inside a div in following way:

<div class="field">
    <label for="name">Name:</label>
    <input type="text" class="input" name="name" />
    <p class="hint">Enter your name</p>
</div>

the hint class is initially hidden like display:none.

How can I display the hidden hint class on hover anywhere in class field. Thanks.

2 Answers 2

19

In CSS you can do it the following way:

.hint { display: none; }
.field:hover .hint { display: block; }

Edit: As Karl said, this will not work in Internet Explorer 6. You can, however, resort to JavaScript (in this example using jQuery) to do that:

jQuery(".field").hover(
   function() {
      jQuery(this).find(".hint").css("display","block");
   },
   function() {
      jQuery(this).find(".hint").css("display","none");
   }
);
Sign up to request clarification or add additional context in comments.

Comments

2

This option will work in IE 4 and later.

<div class="field" onmouseover="document.getElementById('hint').style.display='none';"  onmouseout="document.getElementById('hint').style.display='block';">
    <label for="name">Name:</label>
    <input type="text" class="input" name="name" />
    <p id="hint">Enter your name</p>
</div>

And for your other forms just change the id hint2, hint3, etc.

<div class="field" onmouseover="document.getElementById('hint2').style.display='none';"  onmouseout="document.getElementById('hint2').style.display='block';">
    <label for="name">Name:</label>
    <input type="text" class="input" name="name" />
    <p id="hint2">Enter your name</p>
</div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.