Skip to content

Instantly share code, notes, and snippets.

@valiantboymaksud
Last active November 26, 2022 04:07
Show Gist options
  • Save valiantboymaksud/6f341a65ee9954fa92c24a2bddc70c71 to your computer and use it in GitHub Desktop.
Save valiantboymaksud/6f341a65ee9954fa92c24a2bddc70c71 to your computer and use it in GitHub Desktop.
Auto Select which help to select option value dynamically. You can also select multiple option
const { isArray } = require("lodash");
$('select').each(function() {
let _this = $(this)
let selected = $(this).data('selected');
if (isArray(selected)) {
selected.forEach(element => {
_this.val(element).prop('selected', 'selected')
});
}
if (typeof selected === "undefined") {
return;
}
_this.val(selected).prop('selected', 'selected')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment