Hello Everyone
I have very annoying problem, that I cant solve. I have a <div> that is generated from dll, to which I do not have access. I need to take content of that <DIV> and rearrange it, for display purposes.
I wrote javascript that takes the information from the DIV, parses it and populates <ul> to simulate dropdown.
Problem is I am getting some extra characters that ruin the link.
This is the JS that I use:
Code:
<script type="text/javascript">
function returnArray() {
var divContent = document.getElementById('tribSort');
var parentGuest = document.getElementById("hey");
var lielement = document.createElement('li');
var options = ["Price Low to High", "Price High to Low", "Name A to Z", "Name Z to A", "Bestselling", "Rating", "Recently Added"];
var select = document.getElementById("selectNumber");
var clickvalue = " onClick=\"";
var navodnici = "\"";
var a = new Array();
var b = new Array();
for (var i in divContent.childNodes) {
var lielement = document.createElement('li');
a[i] = divContent.childNodes[i].toString(); // This is Value
b[i] = divContent.childNodes[i].getAttribute("onClick"); // This is onclick
var combined = "http://" + a[i] + navodnici + clickvalue + b[i];
var tet = "<a href=" + a[i] + " onclick=" + b[i] + ">" + options[i] + "</a>";
alert(tet): // this looks fine
lielement.innerHTML = tet;
alert(lielement.innerHTML); // this is not fine
parentGuest.appendChild(lielement);
//<li><a href="#" onclick="showhide('d2');">Lithium-ION</a>
}
// }
return a;
}
function init() {
var a = returnArray();
alert(a)
}
// var ele = document.getElementById("tribSort");
// ele.style.display = "none";
// alert(ele);
</script>
In the code there is first alert statement, and it shows that it is being parsed exactly as it should, as shown in image 1:
After second alert in the code, after I added the variable using innerHTML there are some things that were not there before, underlined in red in the image 2:
I have seen somewhere there are problems using innerHTML, but I dont know th eother way of doing it.
Can someone please help me with this issue?
Thank you very much.