On an HTML5 page with JS that I have to do, I have to simulate RSS with an XML file (which simulates an html with a couple of own tags), which has articles, first showing a header with a link to the description . At the moment, the file reads it and shows well, except for a detail that unbalances me, jumps an undefined for each line that shows, in addition to the content.
JS:
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function()
{
if (this.readyState == 4 && this.status == 200)
myFunction(this);
};
xhttp.open("GET", "data/articles.xml", true);
xhttp.send();
}
function mostrar(x,texto)
{
var listado;
listado+="<div onclick='unhide("+texto+")'> ";
listado+="<p>";
listado+=x.getElementsByTagName("h2")[0].childNodes[0].nodeValue;
listado+="</p>\n";
listado+="</div>\n<hr />\n<br /> \n";
return listado;
}
function myFunction(xml) {
var i;
var listado="";
var x = xml.responseXML.getElementsByTagName("articulo");
for (i = 0; i <x.length; i++)
{
listado+=mostrar(x[i],'a'+i) //Si no llamo a una función externa, sobreescribe lo que ya había
}
document.getElementById("ninguno").innerHTML = listado;
}
XML:
<articulos>
<articulo>
<article>
<h2>TEST</h2>
<p></p>
</article>
<img href=''></img>
</articulo>
<articulo>
<article>
<h2>prueba</h2>
<p></p>
</article>
<img href=''></img>
</articulo>
</articulos>
Result:
The css I doubt it is necessary, but here goes:
div {
border-radius: 25px;
padding: 20px;
width: 200px;
height: 150px;
}
#hidden
{
display:none;
}