Posted By

pogosheep on 08/08/10


Tagged

javascript select option jquery function


Versions (?)

Select the specified option for alle html selects as jQuery.


 / Published in: jQuery
 

Select the specified option for alle html selects as jQuery.

  1. /**
  2.  * Sets for all matched elements (DOM selected as jQuery) the option as selected.
  3.  *
  4.  * @param jQuery A jQuery object. Eg. $('select') or $(selector).
  5.  * @param option The optionvalue that will be selected. Eg. a number or string.
  6.  *
  7.  * @requires jQuery
  8.  * @author pogosheep < [email protected] >
  9.  */
  10. function setActiveSelectOption(jQuery, option) {
  11. $.each(jQuery.children(), function(index, element) {
  12. if ($(element).val() === option) {
  13. $(element).attr('selected', 'selected');
  14. }
  15. else {
  16. $(element).removeAttr('selected');
  17. }
  18. });
  19. }

Report this snippet  

You need to login to post a comment.