Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The following loops through all h2 elements and removes the beginning via a regex replace:</p> <pre><code>window.onload = function() { var h2s = document.getElementsByTagName("h2"), i; for (i=0; i &lt; h2s.length; i++) h2s[i].innerHTML = h2s[i].innerHTML.replace(/^[^-]+ - /,"");​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​ }; </code></pre> <p>Demo: <a href="http://jsfiddle.net/nGfYd/5/" rel="nofollow">http://jsfiddle.net/nGfYd/5/</a></p> <p>The <code>onload</code> handler ensures that the code runs after the page has finished loading, because JavaScript is executed as it is encountered while the page is being parsed, but it can only manipulate elements that have been already been parsed. You don't need the <code>onload</code> handler if you include the code in a script block after the elements in question, in fact my preference is to put the <code>&lt;script&gt;</code> block at the end of the body just before the closing <code>&lt;/body&gt;</code> tag and not use an <code>onload</code> handler.</p> <p>EDIT: From comments under other answers it seems you are happy to use jQuery, in which case you could do this:</p> <pre><code>$(document).ready(function(){ $("h2").text(function(i, oldVal) { return oldVal.replace(/^[^-]+ - /,""); }); }); </code></pre> <p>Demo: <a href="http://jsfiddle.net/nGfYd/7/" rel="nofollow">http://jsfiddle.net/nGfYd/7/</a></p> <p>If you pass a function to <code>.text()</code> jQuery will call that function for each element, passing it the old (current) value of the element, so you don't need an <code>.each()</code> loop too.</p> <p>(Again the document ready handler is not needed if you put the code in a script block at the end of the body.)</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.
 

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