Q:

How to setAttribute a href in a li tag?

I'm coding an intranet. 
I wrote my code in HTML. Now I'm rewriting the HTML code in JS, so that I can add, modify and delete dynamically some content. 
I have to use mySection.setAttribute("class", "myClass"); to give class, id,... to my tags. 
When there is only a class or an id there is no problem. But now I have to rewrite in JS this line : 
<li><a href="https://www.google.ch/" target="_blank">Yahoo</a></li>

I can't solve my problem I have been trying and searching on the internet...but nothing seems to be like my problem.

A:

This might be helpful to achieve your goal.
<script>
$(document).ready(function(){
  var a =document.querySelector("a[href$='.ch']");
  a.setAttribute("class", "democlass");
});
</script>

