$('select[name="slc_pc"]')
.append($('<option />') // Create new <option> element
.val('Hello') // Set value as "Hello"
.text('Hello') // Set textContent as "Hello"
.prop('selected', true) // Mark it selected
.data({ // Set multiple data-* attributes
token: 'abc'
})
);
var report_id = $("#report_list").find(":selected").val();
var token = $("#report_list").find(':selected').attr('data-token');
var fetch_str = '?token=' + token;
if(token == ''){
fetch_str = '?id=' + report_id;
}
Are you sure they're not being added. They won't show up in your inspector or the console, so you won't be able to 'see' if they've been added. You'll need to examing the data property in code to check them. Quick way is to select the <option> in your Inspector and then type $($0).data() into the inspectors command line - that will output the data attributes on your element,