troubleshooting Question

jquery tooltip

Avatar of rivkamak
rivkamakFlag for United States of America asked on
2 Comments1 Solution419 ViewsLast Modified:
I have a simple form fields on my page that I am trying to turn into a tooltip.
I used to have the code in javascript, and I want to switch it to jquery.
The css is all set up.
The code looks like this:
                        <label for="Address" id="AddressLabel" >Address &amp; apt*</label>
						<input name="Address" type="text" id="Address"  title="address" maxlength="50"  x-autocompletetype="street-address"/>
					<span class="hint">Tax receipts are mailed here.<span class="hint-pointer">&nbsp;</span></span>

Open in new window

How can i make a standard code that will work for all fields on my page.
All I want is when someone puts their cursor in the input field, if there is a span with class hint, then .hint  should display inline, when you move out of the field,  change class="hint" to display:none;

This is what is was in javascript, but doesn't work anymore:
	var inputs = document.getElementsByTagName("input");
	for (var i=0; i<inputs.length; i++){
		// test to see if the hint span exists first
		if (inputs[i].parentNode.getElementsByTagName("span")[0]) {
			// the span exists!  on focus, show the hint
			inputs[i].onfocus = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
			// when the cursor moves away from the field, hide the hint
			inputs[i].onblur = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "none";

Open in new window

You can see it on my page, here is works:
here it doesn't:
Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros