Take the 2-minute tour ×

I have a Multi Select List generated by HTML.ListBoxFor. The select element has an id of '#listBox'

I want to add a title attribute to each option tag. The value of the title attribute comes from a Dictionary<string,string>.

I want to do the following

loop through option element of the selectlist and get the text of the option element

loop through each element of Dictionary

Where dictionary.key == text add a title attribute with the value of Dictionary.Value.

share|improve this question
I haven't done jQuery for ages, so i'm pretty much stuck at the first hurdle, of even looping through the option elements of the selectlist –  Doozer1979 Jul 11 '12 at 13:55
$('#yourSelect option').each(function(){..do stuff..}); –  sirrocco Jul 11 '12 at 14:00
@Doozer1979 You will not be able to do that, since you can't loop on your server-side type after you get text client-side with Jquery,since client-side only works after page is rendered. Is there some other way you can get those values from Option Element? Where do you get text from? –  Unavailable Jul 11 '12 at 14:10
The text is the innerHtml of the option element –  Doozer1979 Jul 11 '12 at 14:16
I guess i'll have to get the values into an regular javascript array –  Doozer1979 Jul 11 '12 at 14:16
show 4 more comments

1 Answer

Check out this post Store extra value per item in drop down list. It allows you to put any attributes you want into the option items of a dropdown.

share|improve this answer
add comment

Your Answer


