Click here to Skip to main content
15,896,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a few number of dropdown lists on the page, having options with Value and Text.
I want to add alt tag and title tag to all the options of the dropdown with the help of jquery.
I wrote some code but the thing is not working. The code that i wrote is below-
JavaScript
$('#statusCode option').each(
function () {
var option = $(this);
option.title = option.val;
option.prop('title', option.val);
alert('asd');
});

Over here statusCode is the id of the dropdownlist that i am currently working with.
Please help, provide inputs
Posted

Hi Aditya,

Please try this out and let me know your feed back.



$(document).ready(function () {
var options = $("#statusCode option");
optionlength = options.length;
//option.title = option.val;
//option.prop('title', option.val);
alert(optionlength);
for (var i = 0; i < optionlength; i++) {
$(options[i]).attr("title", $(options[i]).val());
}
});

Thanks :)
 
Share this answer
 
here is a code that i wrote, was doing a small wrong thing-
JavaScript
$('select option').each(
           function () {
               $(this).attr("title", $(this).text());
           });
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900