I have created a dropdown listing last 5 years from current year, current year being selected explicitly. Here is my code:
var nDate = new Date();
var year = nDate.getFullYear();
$('#yearddl').append('<option value>Select Year</option>');
for (var i = 0; i <= 4; i++) {
if (i == 0) {
$('#yearddl').append('<option selected value =' + year + '>' + year + '</option>');
}
else {
$('#yearddl').append('<option value =' + year + '>' + year + '</option>');
}
year = year - 1;
}
Now, my requirement is that how can I check that whether first option, which would in any case be the current year, has selected attribute. Basically, I want to remove selected option from here and give it to some other option.