I want to add a paragraph after every element of type article using the function add in Javascript but it doesn't work . Here is the code I wrote :
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<article> here is one article
</article>
<article> here is the second article
</article>
<script type ="text/javascript">
function add(info)
{
var art = document.getElementsByTagName('article');
var par = document.createElement('p');
par.textContent = info;
var i;
for(i in art)
{
art[i].appendChild(par);
}
};
add("ex");
</script>
</body>
</html>
The ouput I get is : here is one article here is second article ex
Any help would be appreciated ! Thanks!
`.