I have a HTML file that is partially created with javascript/jQuery:
<!DOCTYPE html>
<html>
<head>
<title>with-js</title>
<script type="text/javascript" src="./scripts/jquery-1.11.1.js"></script>
<script type="text/javascript" src="./scripts/object.js"></script>
</head>
<body>
<div id="depiction"></div>
</body>
</html>
The following script object.js
creates additional HTML elements:
jQuery(document).ready(function() {
var svg = jQuery('<svg height="466" width="1842" ></svg>');
var g = jQuery('<g transform="translate(400 200)"></g>');
var t = jQuery('<text text-anchor="middle" x="20" y="26">r1</text>');
var r = jQuery('<rect class="svg_elem" id="elem_1" width="41px" height="40px"></rect>');
g.append(t).append(r).appendTo(svg);
svg.appendTo(jQuery('#depiction'));
});
When I load the HTML file in a browser, the <g>
element is not visible. However, I can recover the complete HTML code using an inspector tool and paste it in another file, removing the reference to the JS script:
<!DOCTYPE html>
<html>
<head>
<title>without-js</title>
</head>
<body>
<div id="depiction">
<svg width="1842" height="466">
<g transform="translate(400 200)">
<text y="26" x="20" text-anchor="middle">r1</text>
<rect id="elem_1" class="svg_elem" height="40px" width="41px"></rect>
</g>
</svg>
</div>
</body>
</html>
Now, the <g>
element is shown correctly when the new HTML file is loaded in the browser!
Can anybody explain this to me?
Thanks in advance