4 ms·
Just typing out loud here: I usually just define a function called Tag which returns a jquery handle to said tag i.e. function tag(name) { return $('<' +
by shaunxcode 16y ago
Just typing out loud here: I usually just define a function called Tag which returns a jquery handle to said tag i.e.
function tag(name) {
return $('<' + name +'></' + name + '>');
}
tag('div').append(
tag('ul').append(
tag('li').html('a'),
tag('li').html('b')))
which would become:
['div',
['ul',
['li', 'a'],
['li', 'b']]]
That seems substantially nicer to look at - but lacks the ability to easily add event handlers etc. that I get w/ the jquery approach. There is no reason it could not be inter-operable though:
['div', tag('span').html('click me').click(function(){alert('clicked')})];