MGames MGames - 11 days ago 7
HTML Question

JQuery Code For Selecting Select Option & Clicking Button Not Working?

Hi I'm tring to select the Large size and click the button from a website. I have the html code in fiddle as well as the jquery code I tried. I've tried these (below), but it doesn't seem to be working. What did I do wrong?

This is for selecting the Large size:

$('select[name="size"] option').filter(function () { return $(this).html() == "Large"; }).attr("selected",true);


This is for clicking the button:

$('#add-remove-buttons').find('.button').trigger('click');


Here is the fiddle for what I've tried:

http://jsfiddle.net/8RnBf/645/

-Thank you

Answer

try this:

$('#size').val($('#size option').filter(function(ind, el) {
  return $(el).text() === 'Large';
}).val());

demo: http://jsfiddle.net/rLerzj08/

Comments