So I have a table of image metadata that is dynamically built from an API call when a page is loaded, and after uploading new images the function that builds the table is called again to include the new image data. However, the CSS styles for the column width is not rendering on the page (even though it appears perfectly fine in Inspect Element!). Other styles for the columns such as text-align
work after the table is rebuilt. Refreshing the page shows the correct styling. Attached below is my function.
function getMedia(blockName) {
$(".illustrationsContent").empty();
$("#filterTestKey").empty();
$.ajax({
url: [url] + blockName.trim(),
type: 'GET',
dataType: 'json',
async: false,
success: function (media) {
var testKeys = [];
if (media.length > 0) {
$(".illustrationsNoContent").hide();
} else {
$(".illustrationsNoContent").show();
}
for (var i = 0; i < media.length; i++) {
var newRow = "<tr class='illustrationsContent'><td style='width: 20%;'>" + media[i].Question + "</td>"
+ "<td>" + media[i].Name + "</td>"
+ "<td style='text-align: center; width: 15%'>" + "<button type='button' class='delete' disabled>Delete</button>" + "</td></tr>";
testKeys.push(media[i].Question);
$("#illustrationsTable tbody").append(newRow);
}
testKeys = jQuery.uniqueSort(testKeys);
if (testKeys[0] == blockName) {
$("#filterTestKey").hide();
$("#TestKeyLabel").show();
} else {
$("#TestKeyLabel").hide();
$("#filterTestKey").append(new Option("All Test Keys", "All Test Keys"));
for (var i = 0; i < testKeys.length; i++) {
$("#filterTestKey").append(new Option(testKeys[i], testKeys[i]));
}
}
}
});
}
Thanks