How to select an dropdown option via javascript?

Topic: How to select an dropdown option via javascript?

salmanfazal01 pro asked 3 months ago

How do I dynamically change the option from a select dropdown using javascript or jquery?

My html code:

<select class="mdb-select md-form" id="symbol" searchable="Search here..">
    <option value="ABC">ABC</option>
    <option value="XYZ">XYZ</option>
    <option value="SDA">SDA</option>

This is what I have tried till now:

$('select[id="symbol"] li:contains("XYZ")').trigger('click');

Piotr Obrebski staff answered 3 months ago

Hi salmanfaxal01,

I creaded simple snippet with solution to your request:

If you need additional help I am here for you.

Best Regards, Piotr

Please insert min. 20 characters.


Specification of the issue
  • User: Pro
  • Premium support: No
  • Technology: jQuery
  • MDB Version: 4.8.2
  • Device: Chrome
  • Browser: Chrome
  • OS: Chrome
  • Provided sample code: No
  • Provided link: No