Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Performance-wise, I'd recommend a <code>span</code> hell.</p> <pre><code>&lt;span id="string"&gt;&lt;span id="h"&gt;12&lt;/span&gt;&lt;span class="h"&gt;h&lt;/span&gt;&lt;span id="m"&gt;12&lt;/span&gt;&lt;span class="m"&gt;m&lt;/span&gt;&lt;span id="s"&gt;12&lt;/span&gt;&lt;span class="s"&gt;s&lt;/span&gt;&lt;/span&gt; </code></pre> <p>One span for each <code>h</code>, <code>m</code> and <code>s</code> letters so you can style them properly (can apply either the same or different styling for each).</p> <p>And another span for each number so you can cache the references. In sum, here's a JS for a very simplistic local-time clock:</p> <pre><code>//cache number container element references var h = document.getElementById('h'), m = document.getElementById('m'), s = document.getElementById('s'), //IE feature detection textProp = h.textContent !== undefined ? 'textContent' : 'innerText'; function tick() { var date = new Date(), hours = date.getHours(), mins = date.getMinutes(), secs = date.getSeconds(); h[textProp] = hours &lt; 10 ? '0'+hours : hours; m[textProp] = mins &lt; 10 ? '0'+mins : mins; s[textProp] = secs &lt; 10 ? '0'+secs : secs; } tick(); setInterval(tick, 1000); </code></pre> <p><a href="http://jsfiddle.net/rsfax/2/" rel="noreferrer"><strong>Fiddle</strong></a></p> <p>This illustrates the basic idea of cached selectors. By not re-creating the elements, you also have a good performance boost.</p> <p>Though, once a second isn't very heavy work for something so simple (unless you have hundreds of clocks in your page).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload