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
Post a Comment