I need to change according to each user a select with companies. I make an ajax call to retrieve the complete select element, if the element contents the "selectpicker" class it gives no error but remains hidden (I guess, just realizing of that class thing took two hours). Retrieving it without any class shows the element, and if I add it later with classListAdd is hidden again. If I load a select with that class from the begining it appears ok. Code below. I put the text of the select retrieved in 'response' for this question.
if(ajaxRequest.readyState == 4){
var response = ajaxRequest.responseText;
console.log(response);
document.getElementById('companies').innerHTML = '<select id="select-multiple" data-size="10" data-width="100%" multiple data-live-search="true" title="Seleccione Empresa" multiple data-selected-text-format="count"><option value="58">-</option><option value="28"> C.A.P.S.A. Capex</option></select>';
document.getElementById('select-multiple').classList.add('selectpicker'); //without this line element shows, with it nothing shows
var testArray = document.getElementById('empresas').value.split(',');
$('#select-multiple').val(testArray); //no javascript error (element should exists)
$('#select-multiple').trigger("change");
}