I have the following JavaScript/jQuery:
$select.append($("<option />")
.val(this.id)
.text(this.text)
.data('name', this.name)
.data('isstorage', this.isstorage));
It correctly sets the <option>
tag's value
and text values. But it doesn't set the data-name
or data-isstorage
attributes.
Can someone tell me what I have wrong here?
Full example:
var $select = $('#myselect');
var x = {
id: 'id',
text: 'text',
name: 'name',
isstorage: 'isstorage'
};
$select.append($("<option />")
.val(x.id)
.text(x.text)
.data('name', x.name)
.data('isstorage', x.isstorage));
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div>
<select id="myselect" />
</div>