There is a construct like <div id="show_chosen_address"></div> , and you need to insert it inside the span block. There are no problems with the creation of a span, its class and its contents, but when I try to insert a span into a block, [object HTMLSpanElement] (via console.log (number_span)) shows everything correctly, what you need to insert).
I do this:

 var div = document.getElementById('show_chosen_address'), number_span = d.createElement('span'); number_span.className = "number"; number_span.innerHTML = "test"; div.innerHTML = number_span; 

    1 answer 1

    either use appendChild , or insert number_span.outerHTML

     var div = document.getElementById('show_chosen_address'), number_span = document.createElement('span'); number_span.className = "number"; number_span.innerHTML = "test"; div.innerHTML = number_span.outerHTML; var div2 = document.getElementById('show_chosen_address2'), number_span2 = document.createElement('span'); number_span2.className = "number"; number_span2.innerHTML = "test2"; div2.appendChild(number_span2); 
     #show_chosen_address, #show_chosen_address2 { border: 1px solid; width: 200px; margin-bottom: 10px; } 
     <div id="show_chosen_address"></div> <div id="show_chosen_address2"></div> 

    • thanks, help) I dig a description of the methods in the documentation - ddeadlink