You don't need all that crazy jQuery! It's simple enough!
var message = "Hello World",
messageEl = document.createTextNode( message );
out.appendChild( messageEl );
<img src="https://i.sstatic.net/V6KuG.gif" width="480" height="1"><sup><sup><sup><sup><sup>**[` [ run with user script ] `](http://scripts.jeremybanks.ca/run-stackexchange-code-0.0.user.js)**</sup></sup></sup>
---
$( out ).append( $( "<p>Hello World</p>" ) );
<img src="https://i.sstatic.net/V6KuG.gif" width="480" height="1"><sup><sup><sup><sup>**[` [ run with user script ] `](http://scripts.jeremybanks.ca/run-stackexchange-code-0.0.user.js)**</sup></sup></sup></sup>
?
---
var message = "Hello World",
messageEl = document.createElement( "p" );
messageEl.textContent = message;
out.appendChild( messageEl );
<img src="https://i.sstatic.net/V6KuG.gif" width="480" height="1"><sup><sup><sup><sup><sup>**[` [ run with user script ] `](http://scripts.jeremybanks.ca/run-stackexchange-code-0.0.user.js)**</sup></sup></sup></sup></sup>
!
---
Want to be able to run your code like that? Just add this line below a code block:
> `<img src="https://i.sstatic.net/V6KuG.gif" width="480" height="1"><sup><sup><sup><sup>**[` [ run with user script ] `](http://scripts.jeremybanks.ca/run-stackexchange-code-0.0.user.js)**</sup></sup></sup></sup></sup>`
Your code's wrapped in a functon under the global context, only given the `out` element as an argument.
---
atest( "TO FAIL | return false", function () { return false; } );
atest( "TO FAIL | do nothing", function () { } );
atest( "TO FAIL | error", function () { throw new Error; } );
atest( "TO FAIL | don't let more than 2 seconds pass", function ( assert, pass, toCleanUp ) {
var start = new Date;
return function poll () {
assert( ((new Date) - start) < 2000, "two seconds must not pass" );
return poll;
}
} );
atest( "return true", function () { return true; } );
atest( "Count to 10 Over 1 Second", function ( assert, pass, toCleanUp ) {
var val = 0,
incInterval = setInterval( incVal, 100 );
function incVal () {
val += 1;
}
toCleanUp(function () {
clearInterval( incInterval );
})
return function poll () {
return ( val > 10 ) ? true : poll;
};
});
atest( "Load /", function ( assert, pass, toCleanUp ) {
jQuery.ajax( "/" ).done(function ( data ) {
pass( "Loaded " + data.length + " chars." );
});
});
atest( "Adding even integers doesn't produce an odd one", function ( assert, pass, toCleanUp ) {
for (var n = -10000; n < 10000; n += 2) {
assert( n % 2 === 0, "" + n + " is not a multiple of two." )
}
pass();
});
/*\
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
atest( name, body( assert, pass, toCleanUp ) ); *
Declares an test with the specifed name and body. It will be *
run synconously with other tests defined syncronously with it. *
*
runaTest( body( assert, pass, toCleanUp ) ); *
Executes a test body and returns a promise of the result. *
*
A test body can return true to pass, false to fail or a function *
to continue to it asyncronously. This happens with a delay, so it *
can be used to poll some state. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
\*/
runaTest.timeout = 5000;
runaTest.tickDelay = 100;
atest.cooldown = 250;
function atest ( name, body ) {
if ( !atest.buffer ) {
atest.buffer = [];
setTimeout( triggerTests, 0 );
}
atest.buffer.push( [ name, body ] );
function triggerTests () {
var buffer = atest.buffer,
i = 0;
delete atest.buffer;
triggerNext();
function triggerNext () {
if ( i < buffer.length ) {
var name = buffer[ i ][ 0 ],
body = buffer[ i ][ 1 ],
testRun = runaTest( body );
testRun.then(function passed () {
$("<p/>").text( [ "pass [" + name + "]" ].concat( [].slice.call( arguments ) ).join(" - ") ).appendTo(out);
}, function failed () {
$("<p/>").text( [ "FAIL [" + name + "]" ].concat( [].slice.call( arguments ) ).join(" - ") ).css("color", "red").appendTo(out);
});
testRun.always(function () {
setTimeout( triggerNext, atest.cooldown );
});
++i;
}
}
}
}
function runaTest ( body ) {
var result = new jQuery.Deferred,
tickInterval = setInterval( tick, runaTest.tickDelay ),
timeoutTimeout = setTimeout( result.reject, runaTest.timeout, "Timeout" ),
active = body;
return result.promise();
function assert ( condition, msg ) {
if ( !condition ) {
var failArgs = [ "Assertion failed" ].concat( [].slice.call( arguments, 1 ) );
result.reject.apply( result, failArgs ) ;
}
}
function tick () {
if ( result.state() === "pending" ) {
if ( typeof active === "function" ) {
try {
active = active.call( result, assert, result.resolve, result.always );
} catch ( ex ) {
result.reject( "Uncaught exception", ex );
$("<p/>").text(ex.stack).appendTo(out);
}
} else if ( active === true ) {
result.resolve();
} else if ( active === false ) {
result.reject();
}
} else {
clearInterval( tickInterval );
}
}
}
<img src="https://i.sstatic.net/V6KuG.gif" width="480" height="1"><sup><sup><sup><sup>**[ ` [ run with user script ] ` ](http://scripts.jeremybanks.ca/run-stackexchange-code-0.0.user.js)**</sup></sup></sup></sup></sup>
---
[tag:l]*[tag:hello-and-welcome-to]*
[tag:l]**[tag:banks--sand--castle+]**
[tag:l]
[tag:l]
[tag:l]
[tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll]
[tag:l] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:l]
[tag:llllll] [tag:llllll] [tag:l] [tag:l] [tag:llllll] [tag:llllll] [tag:llllll] [tag:l] [tag:l] [tag:llllll] [tag:llllll]
[tag:l] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:l]
[tag:llllll] [tag:llllll] [tag:l] [tag:l] [tag:llllll] [tag:llllll] [tag:llllll] [tag:l] [tag:l] [tag:llllll] [tag:llllll]
[tag:llll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llll]
[tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll]
[tag:l] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:l]
[tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll]
[tag:l] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:l]
[tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll]
[tag:l] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:l] [tag:l] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:l]
[tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll]
[tag:l] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:l] [tag:l] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:l]
[tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll] [tag:llllll]
---