javascript - jQuery: set dropdown options selected to the html string -


i appending string containing html main div. string contains dropdown generated function cant modify. string containing html dropdown set option of dropdown , append div

var stringhtml = "<div> <select>"+ somefunction() + "</select></div>"; jquery('#maindiv').append(stringhtml); 

so somefunction() above helps options select , append options

i somthing this

jquery(stringhtml).find("select option[value=\"" + sumevalue + "\"]").attr('selected', 'selected'); 

and append html required value selected

thanks

the problem here still inserting string page. should insert jquery object created when called jquery(stringhtml), because 1 affected code. results should like:

var stringhtml = "<div> <select>"+ somefunction() + "</select></div>"; var html = jquery(stringhtml); //save whole string object html.find("select").val(sumevalue); // alter object jquery('#maindiv').append(html); // insert whole object page 

here fiddle. note slight optimization - there no need create complex option selector, can set value of select itself.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -