How to select an option by its option text using jQuery

Okay so here is a select list below and you need to choose an option by text so you can mark it as selected or trigger a change etc. 

  <option value="test">label</option>
  <option value="test2">label2</option>

Select from option value is pretty easy and it is as below:

$('select option[value="test"]').val();

So now selecting by text, If you are using jQuery and if you have an older version than 1.9 the following will work choosing by text.

$('select option[value="label"]').attr('selected', true);

For more recent versions of jQeury the following works.

$('select option:contains("label")').attr('selected', true);

More from jQuery + Select + HTML