title: HTML - How do I insert a <span></span> tag into each line of a <pre></pre> block without hard coding?
body: <p>I was just trying to add line numbers at the beginning of source code using CSS.
  I realized the effect I wanted, as follows:</p>
  
  <p><a href="https://i.stack.imgur.com/A0P12.png" rel="nofollow"><img src="https://i.stack.imgur.com/A0P12.png" alt="Effect implemented"></a></p>
  
  <p>However, the HTML code required continual use of <code>&lt;span&gt;...&lt;/span&gt;</code> tags:</p>
  
  <pre><code>&lt;pre class="code"&gt;
    &lt;span&gt;var links = document.getElementsByClassName("link");&lt;/span&gt;
    &lt;span&gt;for(var i = 0; i &amp;lt; links.length; i++){&lt;/span&gt;
    &lt;span&gt;  links[i].onclick=function(){&lt;/span&gt;
    &lt;span&gt;   alert(i+1);&lt;/span&gt;
    &lt;span&gt;  };&lt;/span&gt;
    &lt;span&gt;}&lt;/span&gt;
  &lt;/pre&gt;
  </code></pre>
  
  <p>With the <code>span</code> tags positioned at home/end of lines I can let the line numbers show as expected.
  But I think there must be another better solution to prevent me adding all these <code>span</code> tags hard-coded, maybe using Javascript, or jQuery I don't mind but don't know how. Please help.</p>
  
  <p>NOTE:<br>
  My problem is not how to display line numbers when the <code>&lt;span&gt;</code> tags are already there. Instead, I wanted to know if the origin HTML code contains NO <code>&lt;span&gt;</code> tags, how can I automatically add them into the suitable places and so I can apply the CSS styles.</p>