How do you remove all the options of a select box and then add one option and select it with jQuery?
$(‘#mySelect’) .find(‘option’) .remove() .end() .append(‘<option value=”whatever”>text</option>’) .val(‘whatever’) ;
$(‘#mySelect’) .find(‘option’) .remove() .end() .append(‘<option value=”whatever”>text</option>’) .val(‘whatever’) ;
I’d like to contribute some code to Alexei’s answer. A few points: Strictly speaking, it may not always be possible to determine when the page has finished rendering with 100% probability. Some pages are quite complex and use continuous AJAX updates. But we can get quite close, by polling the page’s current HTML snapshot for … Read more