Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
184
rated 0 times [  190] [ 6]  / answers: 1 / hits: 17639  / 11 Years ago, tue, november 26, 2013, 12:00:00

Javascript, Jquery, HTML



I am adding select options to a select box dynamically. I take each unique element in an array and add it as an option to the select element. It works great, but I need to add a title attribute at the same time, with the same value as the option text. The end goal of this is to make tooltips for each option.



So instead of <option>value</option>, it looks like



<option title=value>value</option>


Does that make sense?



Current HTML:



<select id=Process_Issue class=fieldLabel2 IncidentInputField dynamicFields1></select>


JS:



$.each(eliminateDuplicates(aryProcess), function (key, value) { $('#Process_Issue').append($(<option/>, { text: cleanNulls(value) })); });

More From » jquery

 Answers
33

You can just specify the title upon appending:



JSFiddle



HTML



<select id=my_select></select>


JS



$('#my_select').append('<option title=value1>value1</option>');
$('#my_select').append('<option title=value2>value2</option>');
$('#my_select').append('<option title=value3>value3</option>');

[#74048] Monday, November 25, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jase

Total Points: 442
Total Questions: 107
Total Answers: 94

Location: Sao Tome and Principe
Member since Wed, Dec 29, 2021
2 Years ago
;