jquery set selected attribute on an option using like -


how can set ubuntu selected following select box tried following below

<select> <option value="val1">val 1</option> <option value="val2">val 2</option> <option value="val3">val 3</option> <option value="val3">ubuntu -12.04 amd......</option> </select>   $('#image_id').find('option[text="ubuntu"]').attr('selected'); 

try,

$('#image_id').find('option:contains("ubuntu -12.04")').prop('selected',true); 

working demo

so per new request can like,

$('#image_id').find('option:contains("ubuntu"):contains("-12.04")').prop('selected',true); 

working demo


Comments

Popular posts from this blog

How to access named pipes using JavaScript in Firefox add-on? -

multithreading - OPAL (Open Phone Abstraction Library) Transport not terminated when reattaching thread? -

node.js - req param returns an empty array -