title: How to append link to <a> element using Javascript
body: <p>I want to add href to an a html element from class of another element. It might also be good to know that i am using Django.As well i dont want the second url to be visible, when the character is not selected yet. Firstly i have this list:</p>
  
  <pre><code>&lt;ul&gt;
    &lt;a class="1" id="tablink"&gt;A&lt;/a&gt;
    &lt;a class="2" id="tablink"&gt;B&lt;/a&gt;
  ...
  &lt;/ul&gt;
  </code></pre>
  
  <p>if list from the first ul is selected, i want the class of the list (example: A) to add to href element to all links in another ul:</p>
  
  <pre><code>&lt;ul&gt;
  &lt;a href="{% url id=id character= &lt;!--here i want the number selected to be inserted--&gt; %}"&gt;One&lt;/a&gt;
  &lt;a href="{% url id=id character= &lt;!--here i want the number selected to be inserted--&gt; %}"&gt;Two&lt;/a&gt;
  ...
  
  &lt;/ul&gt;
  </code></pre>
  
  <p>Thank you!
  EDIT:
  I have this code now:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
  $(".tablinks").on("click", function(){
    var char = this.getAttribute("id");
    document.getElementById("subjects").href = "{% url 'subject_id' letnik_id=letnik_id classes_id=classes_id subject_id=" + char + " %}";
  
    });
  &lt;/script&gt;
  </code></pre>
  
  <p>But it has a problem:
  It only works if i add attribute to element that i got with ID, so id doesnt work with</p>
  
  <pre><code>&lt;a class="subjects"&gt;Hello&lt;/a&gt;
  doucment.getElementsByClassName("subjecs").href = ...
  </code></pre>
  
  <p>and the DJango url doesnt work (<code>"{% url 'subject_id' letnik_id=letnik_id classes_id=classes_id subject_id=" + char + " %}"</code>). </p>