jquery remove/hide list option not containg string value from other list -


i have problem updating select options.

<select id="all">     <option value="volvo_a">volvo_a</option>     <option value="volvo_b">volvo_b</option>     <option value="volvo_c">volvo_c</option>     <option value="saab_a">saab_a</option>     <option value="saab_b">saab_b</option>     <option value="saab_c">saab_c</option>     <option value="saab">saab</option>     <option value="mercedes_a">mercedes_a</option>     <option value="mercedes_b">mercedes_b</option>     <option value="mercedes_c">mercedes_c</option>     <option value="mercedes">mercedes</option>     <option value="audi_a">audi_a</option>     <option value="audi_b">audi_b</option>     <option value="audi_c">audi_c</option> </select>  <select id="type">     <option value="volvo">volvo</option>     <option value="saab">saab</option>     <option value="mercedes">mercedes</option>     <option value="audi">audi</option> </select> <button type="button" id="filter">filter</button> 

i want update select list id based on value select list id type using jquery. example if volvo selected select id type, option not contain volvo in select list id should hidden temporarily. how can achieve this.

i tried following code did not work.

$( "#filter" ).click(function( event ) {   var filter = $("#type").val();   $("#all > option[value != filter]").remove(); }); 

http://jsfiddle.net/h2ecw/

$( "#filter" ).click(function( event ) {   var filter = $("#type").val();     console.log($("#all > option:not([value^=\"volvo\"])"));             console.log(filter);     $("#all > option").show();     $("#all > option:not([value^=\""+filter+"\"])").hide();     $("#all").val($('#all>option:visible:first').val());            //$("#all > option:not[value ^= "+filter+"]").remove(); }); 

hide/show instead of remove..


Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -