How to run javascript / jQuery before document ready

You can add no_doc_ready inside you variation code to override document ready.

/* no_doc_ready */

If you would like some of the code to run before document ready, and some after, simply write like this:

/* no_doc_ready */
$("h1").text("example");

$(document).ready(function(){
   /* Code that you want after document ready */
});

You can also do an interval for reliable and fast execution (Advanced):

var addlinks = function() { 
  $("a:not(.sg_changed)").each(function() { /* Loop all unchanged elements */
    $(this).addClass('sg_changed'); /* When unchanged element is changed, add class to it so it won't be affected again */
    $(this).text('New text for all links...'); /* Do whatever change you want to do */
  }); 
}
 
addlinks(); /* Run links function from start */

var sg_interval1 = setInterval(function() {
  addlinks(); /* Run links function 3 times every second (Could be set to faster or slower depending on needs) */
},300);
 
$(document).ready(function() {
  clearInterval(sg_interval1); /* Clear interval on document ready since all elements should have loaded by then. */
});