I have a function that needs to be fired on window load only if there on page is no option elements that has "selected" attribute.
<option value="1" selected="selected">Option</option> I tried to do this with no luck with next function:
function fireWhenLoad () { if ( $('select option').is(':selected')) { alert("Selected"); } else { alert("Not Selected"); runIfNoSelectedOptions(); } }; $(window).load(function(){ fireWhenLoad(); }); The function alerts "Selected" in every case if options has "selected" attribute and if they don't.
So what am I doing wrong and how can I check if option element has "selected" attribute?
Thank you!