Hello my jQuery friends,

I received a comment on learningjquery.com this evening from someone who had a grievance with part of some example code. I was wondering if any of you would be willing to shed some light on this for me. I think what he's getting at is the whole "innerHTML is evil" thing, but since he doesn't really explain why he think it's "really ugly," I'm just not sure.

Here is the relevant snippet of his comment:

Nice post, but …
This part of code :

$('#show-alert').click(function() {
$('<div class="quick-alert">Alert! Watch me before it\'s too late!</ div>') .insertAfter( $(this) );
}

should be AVOIDED as is. Inserting HTML code like this is really ugly, it’s a lot better to use the DOM methods :

$('#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);
}
I'd love to hear your opinions about this. With HTML/CSS stuff, I'm obsessed with standards and such. And one of the things that has always really attracted me to jQuery is its unobtrusiveness. I also read Jeremy Keith's DOM Scripting book and really appreciated his approach -- which is similar to what this commenter is suggesting. But I also love the super-fast development that can be done with jQuery and don't want to have to give that up if it's just a matter of someone's aesthetic sensibility being offended. I guess I just want to do the right thing.

thanks,

--Karl
_________________
Karl Swedberg
www.englishrules.com
www.learningjquery.com



_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to