On Tue, 28 Aug 2012 10:40:23 -0700, Niklas Laxström niklas.laxstrom@gmail.com wrote:
On 28 August 2012 02:26, Daniel Friesen daniel@nadir-seen-fire.com wrote:
I ran into our coding conventions for creating elements in JS: https://www.mediawiki.org/wiki/Manual:Coding_conventions/JavaScript#Creating... var $hello = $('<div>').text( 'Hello' ); // Not '<div/>' // Not '<div></div>'
This looks like some really bad advice.
The very reason I and others have been killing '<div/>' with fire is that I was told it doesn't work in IE. Can you explain what is going on?
If they're talking about jQuery that's a mistake on part of whoever told you that.
jQuery has a regexp internally that converts <tag ... /> anywhere in the input automatically into <tag ...></tag>. It's an intentional shortcut so that you don't have to specify the closing tag every time you're creating an element that you're going to add content to dynamically.
Personally I don't like '<div/>' because there is no such thing in html. I could understand '<div>' as a shortcut for creating a div element.
Unless the issue is clarified, I think that recommending to always use valid html like <div></div> seems a much better option than either of
<div> or <div/>.
What would you think about bypassing all the pointless vs. discussion by adding something like `$.tag( 'div' )` or `$.create( 'div' );`?
-Niklas