Thanks, everyone, for the excellent responses to my question. I knew
I could count on this group to provide well informed, well reasoned
advice.
To be fair to the commenter, he did mention one of the DOM creation
plugins (I just didn't include that part of the comment in the
original post):
Or, with the DOMCreate plugin for jQuery :
$('#show-alert').click(function() {
var oDiv = jQuery.create('div', {'class':'quick-alert'}, ["Alert !
Watch me before it's too late !"]});
$(this).after(oDiv);
}
Thanks also for the links to other resources on the innerHTML matter.
I've been reading the excellent PPK on JavaScript, so I thought I'd
add a couple quotes from that book into the mix:
Even though officially it's a Microsoft proprietary property, it is
supported by all modern browsers, and is a required item in the bag
of tricks any JavaScripter should carry...
innerHTML is not a part of the W3C DOM specification. For some
people, that's reason enough not to use it. Personally, I disagree
sharply ...innerHTML is excellently suited for some tasks, and it
has perfect browser compatibility.
You'll have to decide this for yourself, but I don't see any good
reasons for refusing to use innerHTML. Instead, we should try to
find out in which situations innerHTML will work better than pure
DOM methods, and in which situations the pure methods will have the
advantage...
Since innerHTML is so powerful, you should take care to always pass
it correct HTML. Garbage HTML can cause very weird effects....
- PPK on Javascript, Peter-Paul Koch. 380, 381.
Cheers, everyone, and thanks again for all the excellent input!
--Karl
_________________
Karl Swedberg
www.englishrules.com
www.learningjquery.com
On Feb 1, 2007, at 2:56 AM, Klaus Hartl wrote:
Joel Birch schrieb:
On 01/02/2007, at 12:30 PM, Karl Swedberg wrote:
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.
Here is my current understanding of this issue. (Anyone, please
correct me where I am wrong). The main reason why innerHTML is said
to be evil is that it is not part of the standards. Therefore, if a
vendor creates a new user agent they may not decide to implement
support for it, leaving your web app or site broken and probably
adversely affected accessibility-wise. Whilst it is hard to imagine
any new browsers not supporting innerHTML as it is what some people
call a "pseudo-standard", I suppose it is not as hard to imagine
various new mobile devices and other unconventional browsers
supporting JavaScript but not what they may consider "extras" such as
innerHTML.
Also, if you ever want to serve the page as XHTML your script will
not work because innerHTML does not work for XML pages of course.
Personally, I have just resigned to using it when using jQuery
because the ease and speed benefits you mentioned are just too darn
seductive. The code is also much more readable so less-techy people
can possibly change the output easier.
I'll be interested to hear what other people think about this.
Joel Birch.
Joel, I couldn't have said it better. You read my mind.
-- Klaus
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/