Editing makedom3 This edit will create a new revision. Your details (optional) Name Email (won’t be displayed; might be used for Gravatar) URL Test case details Title * Published (uncheck if you want to fiddle around before making the page public) Description (in case you feel further explanation is needed)(Markdown syntax is allowed) Are you a spammer? (just answer the question) Preparation code Preparation code HTML (this will be inserted in the <body> of a valid HTML5 document in standards mode) (useful when testing DOM operations or including libraries) <script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <script> function makeDOM(o,to){ var ele = document.createElement(o.element); for (var prop in o.props) { ele.setAttribute(prop, o.props[prop]); } ele.innerHTML = o.contents; return ele; } (function( $, undefined ) { //el can be one of two things: // 1. { tagname: [ { attr: value, ... }, [ children ]] } // 2. "a string" function mkEl( el ) { var ret, key, attr, children, child; if ( $.type( el ) === "string" ) { ret = document.createTextNode( el ); } else { for ( key in el ) { ret = document.createElement( key ); for( attr in el[ key ][ 0 ] ) { ret.setAttribute( attr, el[ key ][ 0 ][ attr ] ); } children = mkChildren( el[ key ][ 1 ] ); for( child in children ) { ret.appendChild( children[ child ] ); } } } return ret; } function mkChildren( c ) { var ret = [], idx; for ( idx in c ) { ret.push( mkEl( c[ idx ] ) ); } return ret; } $.createDom = function( j ) { return ( ( $.type( j ) === "object" ) ? mkEl( j ) : ( ( $.type( j ) === "array" ) ? mkChildren( j ) : undefined ) ); }; })( jQuery ); </script> Include JavaScript libraries as follows: <script src="//cdn.ext/library.js"></script> Define setup for all tests (variables, functions, arrays or other objects that will be used in the tests) (runs before each clocked test loop, outside of the timed code region) (e.g. define local test variables, reset global variables, clear canvas, etc.) (see FAQ) Define teardown for all tests (runs after each clocked test loop, outside of the timed code region) (see FAQ) $(".foo").remove(); Code snippets to compare Test 1 Title Async (check if this is an asynchronous test) Code $("<a id='foo' class='foo' href='/foobar.html'><span class='bar'>foo</span></a>").appendTo('body'); Test 2 Title Async (check if this is an asynchronous test) Code var linkElement = document.createElement( 'a' ); linkElement.href = '/foobar.html'; linkElement.className = "foo"; linkElement.id = "linkid"; linkElement.innerHTML = "<span class='bar'>foo</span>"; $( linkElement ).appendTo( "body" ); Test 3 Title Async (check if this is an asynchronous test) Code var ele = { 'a':[ { 'id':"foo", 'class':'foo', 'href':'/foobar.html' },[{"span":[{class:'bar'},["foo"]]}]] } $($.createDom(ele)).appendTo('body'); Test 4 Title Async (check if this is an asynchronous test) Code var ele = makeDOM({ "element":"a", "props":{ "className":"foo", "href":"/foobar.html", "id":"linkid" }, "contents":"<span class='bar'>foo</span>" },"body"); $(ele).appendTo('body');