InnerHTML removing a trailing slash from an image tag

Very strange, can someone help me. Here is a quick test function:

function test_function(){
    code = '<img src="http://www.myimage.com/img.jpg" alt="image" />';
    alert(code);
    document.getElementById('test').innerHTML = code;
    alert(document.getElementById('test').innerHTML);
}

Execution of the above code will show />in the first warning, but the second warning does not show, it only shows >. So it seems that applying to .innerHTMLremoves a slash. Any ideas how to stop this? I need a slash to check.

+3
source share
1 answer

, . , , JavaScript, DOM.

, XHTML , HTML, XML- . XHTML MIME application/xhtml+xml, XML.

. Ian Hickson .

+6

Source: https://habr.com/ru/post/1776182/


All Articles