Interact with newly created html via javascript

I would like to add a new div from javascript to my existing html page. I usually do this using the document.createElement ("div") statement, and I populate this div with the div.innerHTML = "" method (for example). In most cases, this works great, but now I would like to add a select list to my div and populate these lists with some data. This method does not work:

function initEdit(){
     addPanel = document.createElement("div");
     addPanel.innerHTML = "<form id='addProperty' method='get'> <table>" +
                                "<tr> <td> <select size='4' style='width:140px; height:200px' id='object_property_selection' onClick='unSelect(\"data_property_selection\")'> </td>" +
                                     "<td> <select size='4' style='width:140px; height:200px' id='object_selection'>" +
                                          "<textarea style='width:140px; height:200px; display:none' id='data_selection' /> </td> </tr>" +
                                "<tr> <td> <select size='4' style='width:140px; height:100px' id='data_property_selection' onClick='unSelect(\"object_property_selection\")'> </td>" +
                                     "<td> </td> </tr>" +
                                "<tr> <td colspan=2> <input type='button' name='Submit' style='width:100%' onClick='submitProperty()' /> </td> </tr>" +
                            "</table> </form>";

    $('body').jAlert(contents, 'info', offset);
    list1.forEach(function(element, id){
        var option = document.createElement("OPTION");
        option.text = option.value = property;
        form.data_property_selection.options.add(element);
    })
}

Does anyone know how to solve this? (By the way: I cannot install this html code on the page at the beginning, because this is the content of the jAlert div)

update: solution

properties1.concat(properties2).forEach(function(property, id){
    if (id < object_properties.length) propertyList1 += "<option value='" + property + "'>" + property + "</option>";
    else propertyList2 += "<option value='" + property + "'>" + property + "</option>";
})
objects.forEach(function(feature, id) {
    objectList += "<option value='" + feature._id + "'>" + feature.name + "</option>";
})

propertyList = "<form id='addProperty' method='get'> <table>" +
                            "<tr> <td> <select size='4' style='width:140px; height:200px' id='object_property_selection' onClick='unSelect(\"data_property_selection\")'>" +
                                       propertyList1 + "</select> </td>" +
                                 "<td> <select size='4' style='width:140px; height:200px' id='object_selection'>" +
                                       objectList + "</select> </td>" +
                                      "<textarea style='width:140px; height:200px; display:none' id='data_selection' /> </td> </tr>" +
                            "<tr> <td> <select size='4' style='width:140px; height:100px' id='data_property_selection' onClick='unSelect(\"object_property_selection\")'>" +
                                       propertyList2 + "</select> </td>" +
                                 "<td> </td> </tr>" +
                            "<tr> <td colspan=2> <input type='button' name='Submit' style='width:100%' onClick='submitProperty()' /> </td> </tr>" +
                        "</table> </form>";
+3
source share
1 answer

, , , . innerHTML , createElement . jQuery .

, jQuery: , API.

, , innerHTML ( , innerHTML).

+3

All Articles