MGames MGames - 1 year ago 58
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:


Here is the fiddle for what I've tried:

-Thank you

Answer Source

try this:

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