You are trying to modify DOM (addClass) of the element that is not yet loaded. Try this approach instead:
var _loadFile = function(filename, container, errorMessage) {
return $.ajax({
url : filename,
type: "GET",
cache: false,
dataType: "html",
success : function (data) {
$(container).html(data);
}
});
}
_loadFile('assets/data/html/file.html', '#containerID', 'errorMessage')
.then(function() {
$(idActive).addClass('active');
});
$.ajax
returns promise object, and you use then
method of it. You could also move $(idActive).addClass('active');
inside success callback, but it's not nice: I assume that _loadFile
is a generic function and we don't want it to be aware of anything else but loading data.