JSFiddle - React, Tailwind, and code Playground
by frumbert
HTML
<select name="response[496]" id="id_response_496">
<option value="">Choose...</option>
<option value="answer 4">answer 4</option>
<option value="an image">an image</option>
<option value="blue">blue</option>
<option value="bucket">bucket</option>
</select>
JavaScript
jQuery.fn.outHTML = function(s) {
return (s)
? this.before(s).remove()
: jQuery("<p>").append(this.eq(0).clone()).html();
}
var $o = jQuery("#id_response_496");
$o.val("bucket");
console.log($o.outHTML());
console.log($o.val()); // should show "bucket"
jQuery("option[value='an image']","#id_response_496").prop("selected",true).attr("banana","yellow");
console.log($o.outHTML());
console.log($o.val()); // should show "an image"