Line selection without Javascript
Code & demo
Click on line numbers to select them.
HTML:
1 2 3 4 5 6 7 8 9 10 11 12 13
<div class="container"> <pre class="lines"> <a id="L1" href="#L1">1</a> <a id="L2" href="#L2">2</a> <a id="L3" href="#L3">3</a> ... </pre> <pre class="code"> code… goes… here… </pre> </div>
CSS:
Notes
- In the examples, code within
<pre>
tags is indented for readability, but in practice it should not have leading spaces. - For multiple code blocks on the same page, unique line IDs must be used.
Support
All major browsers.