Hi,
> Hence 7 lines instead of 4.
Nope. Without a DOM-builder plugin I would write this
> >> $('#show-alert').click(function() {
> >> var oDIV = document.createElement('div');
> >> oDiv.className = 'quick-alert';
> >> oText = document.createTextNode("Alert! Watch me before it's too late!");
> >> $(oDiv).append(oText);
> >> $(oDiv).insertAfter(this);
> >> }
that way:
$('#show-alert').click(function() {
$(document.createElement('div'))
.addClass('quick-alert')
.text("Alert! Watch me before it's too late!")
.insertAfter(this);
});
5 Lines with readability optimization, 1 without ;-)
Daves solution is even shorter than yours, but you need to load the
DOM-builder plugin first. Using olsows DOM-builder plugin
http://mg.to/2006/02/27/easy-dom-creation-for-jquery-and-prototype#comment-176
you would write:
$('#show-alert').click(function(){
$(this).after($.create('div',{'class':'quick-alert'},
["Alert! Watch me before it's too late!"]));
});
That is a bit longer than daves solution, but on the other hand olsows plugin
is very small.
Christof
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/