Consider the following HTML structure:
<article id="1919">
<div class="entry-content clearfix">
<div></div>
<div></div>
</div>
</article>
<article id="1910">
<div class="entry-content clearfix">
<div></div>
<div></div>
</div>
</article>
The goal is to insert a link into each div with the class "entry-content clearfix" for all articles.
Can this be achieved using JavaScript?
// Select all elements with the class name 'entry-content'
var eventi_programma=document.getElementsByClassName('entry-content');
// Loop through these elements
for(var i=0;i<eventi_programma.length;i++){
var link="http://www.google.it";//(EXAMPLE LINK);
eventi_programma[i].parentElement.innerHTML='<a href="'+link+'" ><div class="entry-content clearfix">'+eventi_programma[i].outerHTML+'</div></a>';
}
However, the code provided above does not seem to work as expected.