Closed zenlor closed 12 years ago
That hanging m[0]
looks like a remnant of something older, it's certainly not necessary now. I've put this in to #50 too.
But regarding the rest, I'm not convinced that there is a clear enough use-case that isn't solved by other methods. .html()
is for putting unescaped text into elements, which in some special cases requires some special appendChild()
work, but only because of browser oddities.
What I think you're suggesting can already be achieved with any of these variations (and more!):
$('<div id="div1">').appendTo($('body'))
$.create('<div id="div2">').appendTo($('body'))
$('body').append('<div id="div3">')
$('body').append($('<div id="div4">'))
$('body').append($.create('<div id="div5">'))
(This is from Ender with Bonzo + Qwery but they all use Bonzo to do the creating and inserting, the first one is special but only because Qwery knows to pass it on to Bonzo).
.html()
method, before appending clears the element so it's more like:
$('<div if="foo">').appendTo($('body').clear());
$('foo').clear().append($('<div>'))
by the way it's just a small bit of jquery-like compatibility, is not meant to be the right way to achieve it.
I'm +1 on this, as I've run into the same situation.
I don't think you should have some functions accept DOM elements (or Bonzo objects), and some not.
@benvinegar, agreed, not to mention it's conceptually confusing for functions that perform similar tasks. (append(), before(), after() etc...)
don't know if it was intended, but, calling
$('#id').html($('<div>'))
usedel.innerHTML
instead ofappendChild()
as http://jsfiddle.net/UwzVF/1/resulted in:
there is a small caveat, in the code I could see a reference to
(m = el.tagName.match(specialTags))
callingappend(el, m[0])
, butappend
used only the first argumentel
, in this patch I removed it. Was it some planned unfinished feature?