I'am trying to dynamically add an attribute to my HTML
element. After the operation, the attribute is successfully added, but I can't see it in my HTML via the browser console. What's odd is this case, it's the fact that I can display the value of the attribute using console.log
.
let xhr = new XMLHttpRequest();
xhr.responseType = 'json';
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
let result = xhr.response;
appendFileIdsToExtraFields(result.ids,source)
}
};
The appendFileIdsToExtraFields
it's the method in charge of adding the new attribute.
$(ids).each(function (key, value) {
$('#file-'+(key+1)+'-description').attr('data-id',value);
console.log($('#file-'+(key+1)+'-description').data('id'));
});
And here's the value displayed in the console
But not in the element