I am trying to load (append) a couple of documents into HTML, one tag specifically and then do some operations on the loaded files like count the number of some tags, append more tags, put some items into array and similar.
The files I am loading are all SVG files, that have a similar structure with xml and searching through tags with jQuery is simple. But it doesn't seem to work.
I get the svg's to display and when I try to search for a specific tag I get null as a result...
This is the example of the code I have:
HTML:
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="stilovi/style.css">
<title>Testing</title>
</head>
<body>
<div id="avengers">
<svg id="Layer_3" x="0" y="0" viewBox="-400 -100 1000 1000" xml:space="preserve" enable-background="new -400 -100 1000 1000"></svg>
</div>
</body>
And the script bellow I have for appending the files into html:
<script src="jquery-3.1.0.min.js"></script>
<script>
$(document).ready(function(){
var svgArray = ['capt_am_optimizirano1.svg','hulk_optimizirano1.svg', 'iron_man_optimizirano1.svg']
$.each ( svgArray, function (index, data){
$.get( data, function(data){
$(data).find("style").appendTo("#Layer_3");
$(data).find("g").appendTo("#Layer_3");
});
});
var amerpoly = document.getElementById('amer');
console.log(amerpoly);
});
</script>
Am I doing this incorrectly? Is there another way to load files into html and then use its contents for further processing?