Member Avatar

I have a drop down menu with options. Is there a faster way to display a tool tip based on the value of the <option> tag other than having to manually set title="" for each <option> tag?

Recommended Answers

You can do it with script, but you still have to write all the tooltips. Do you want all the same or different tooltips?

Jump to Post

All 3 Replies

You can do it with script, but you still have to write all the tooltips. Do you want all the same or different tooltips?

Member Avatar

You can do it with script, but you still have to write all the tooltips. Do you want all the same or different tooltips?

The tool tip will be based on the value of the option tag's value (as stated). If the value of an option = "Walnut", then I want the tool tip to read "Walnut" when that option is hovered.

I get it.

<body>
<select>
  <option class = 'volvo' value="volvo">Volvo</option>
  <option class = 'saab' value="saab">Saab</option>
  <option class = 'mercedes' value="mercedes">Mercedes</option>
  <option class = 'audi' value="audi">Audi</option>
</select>
<script type='text/javascript'>
$(document).ready(function(){
	$("select option").each(function(){
		var title = $(this).attr('value');
		$(this).attr("title", title);
	});
});
</script>
</body>

Now you got it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.