0

I have a select which is accessible only by name. I need to set the option with particular text in the select.

This is what I have now:

var selection = $("[name='wpv-collection']");
$(selection).filter(function() {
  window.alert($(this).text());
  return $(this).text().includes(s);
}).prop('selected', true);

but the $this.text() is including all options.

Can someone help with what is wrong pls?

freedomn-m
  • 24,983
  • 7
  • 32
  • 55
Maria
  • 21
  • 3
  • 1
    You're targeting the `select` element, not it's options. Change `var selection = $("[name='wpv-collection']");` to `var selection = $("[name='wpv-collection'] option");` – Rory McCrossan Feb 25 '22 at 11:38

0 Answers0