Now I know it might seem as a duplicate, but it isn't. I read all other posts with this title, but couldn't find an answer. I have:
<ul>
  <a id="A" class="tablink">A</a>
  <a id="B" class=tablink">B</a>
...
</ul>
I want the id of above elements, to be href of another list elements from another unordered list.
<ul>
  <a id="1" class="subjects" >1</a>
  <a id="2" class="subjects">2</a>
</ul>
I already have this code
<script type="text/javascript">
$(".tablink").on("click", function(){
  var char = this.getAttribute("id");
  var link = document.getElementsByClassName("subjects").getAttribute("id");
  document.getElementsByClassName("subjects").href = char + link
  });
</script>
But it shows the error in the title. It works if I set: document.getElementById("subjects") and I also have to change subjects to id not to class. So it only works for one element, but I have more of them, so I assume that I have to do some kind of for loop?
EDIT: COuld that be done with jQuery, without for loop? If yes, how?
 
     
     
    