Re: [Wikitech-l] $( 'div' ) vs. $( 'div /') in coding conventions (and methods for building DOMs with jQuery)

2012-08-30 Thread Daniel Werner
In that case, perhaps we should just say that all of the options are fine: $( 'div' ) $( 'div/' ) $( 'div/div' ) but emphasize not to use attributes in the tag creation. +1 All three will return the same, and this is not HTML, it's JavaScript. It really is just a matter of personal flavor

Re: [Wikitech-l] $( 'div' ) vs. $( 'div /') in coding conventions (and methods for building DOMs with jQuery)

2012-08-30 Thread Trevor Parscal
On Thu, Aug 30, 2012 at 3:24 AM, Daniel Werner daniel.wer...@wikimedia.dewrote: By the way, you can also use $( 'div/', { 'class': 'foo', 'title': 'myTitle', ... } ); Just be aware this also allows you to use things like 'html' and 'text' which are not attributes at all, but call .html() or

Re: [Wikitech-l] $( 'div' ) vs. $( 'div /') in coding conventions (and methods for building DOMs with jQuery)

2012-08-29 Thread Tei
I will rescue two facts listed in this thread, about using jquery and creating tags [quote][1] Basically $( 'span class=foo' ) will break completely in IE7/IE8. [quote][2] It's important to note however that IE required that input and button tags are created with a type (if they are going to

Re: [Wikitech-l] $( 'div' ) vs. $( 'div /') in coding conventions

2012-08-28 Thread Tim Starling
On 28/08/12 13:04, Daniel Friesen wrote: I still can't believe the high-level jQuery answer after all these years to Select a div with an id provided by the user is Use `$( div# + userInput )` and hope there are no special characters. Or find some way to escape it yourself. when low-level dom

Re: [Wikitech-l] $( 'div' ) vs. $( 'div /') in coding conventions

2012-08-28 Thread Tei
On 28 August 2012 09:57, Tim Starling tstarl...@wikimedia.org wrote: On 28/08/12 13:04, Daniel Friesen wrote: I still can't believe the high-level jQuery answer after all these years to Select a div with an id provided by the user is Use `$( div# + userInput )` and hope there are no special

Re: [Wikitech-l] $( 'div' ) vs. $( 'div /') in coding conventions

2012-08-28 Thread Trevor Parscal
On Tue, Aug 28, 2012 at 12:57 AM, Tim Starling tstarl...@wikimedia.orgwrote: Personally, I would use document.getElementById() to do that. It's standard, and it's faster and more secure. I think your premature optimization disorder (POD) is flaring up again. jQuery performance is something

Re: [Wikitech-l] $( 'div' ) vs. $( 'div /') in coding conventions

2012-08-28 Thread Tim Starling
On 28/08/12 19:11, Trevor Parscal wrote: On Tue, Aug 28, 2012 at 12:57 AM, Tim Starling tstarl...@wikimedia.orgwrote: Personally, I would use document.getElementById() to do that. It's standard, and it's faster and more secure. I think your premature optimization disorder (POD) is flaring

Re: [Wikitech-l] $( 'div' ) vs. $( 'div /') in coding conventions

2012-08-28 Thread Ryan Kaldari
Yes, $( 'div/' ) or $( 'div/div' ) is correct here, not $( 'div' ). jQuery specifically states this in their documentation, and you'll run into problems in IE if you use the other form (as Neil discovered while writing UploadWizard). Not sure why this is flame-war worthy. Seems pretty

Re: [Wikitech-l] $( 'div' ) vs. $( 'div /') in coding conventions

2012-08-28 Thread Jon Robson
I knew there was a good reason I use $( 'div/' ) One of those things I learn then forget why I'm doing it. I've apparently not being following styling guidelines ;-) This is not flame war worthy. This is not about performance it simply causes problems in IE as Daniel points out. Let's just change

Re: [Wikitech-l] $( 'div' ) vs. $( 'div /') in coding conventions

2012-08-28 Thread Trevor Parscal
On Tue, Aug 28, 2012 at 10:06 AM, Jon Robson jdlrob...@gmail.com wrote: I knew there was a good reason I use $( 'div/' ) One of those things I learn then forget why I'm doing it. I've apparently not being following styling guidelines ;-) Actually you were following the guidelines, but they

Re: [Wikitech-l] $( 'div' ) vs. $( 'div /') in coding conventions (and methods for building DOMs with jQuery)

2012-08-28 Thread Rob Lanphier
On Mon, Aug 27, 2012 at 9:39 PM, Chris Steipp cste...@wikimedia.org wrote: On Mon, Aug 27, 2012 at 4:37 PM, Mark Holmquist mtrac...@member.fsf.org wrote: I also tried to get an answer about the better between $( 'div class=a-class /' ) and $( 'div /' ).addClass( 'a-class' ), but apparently

Re: [Wikitech-l] $( 'div' ) vs. $( 'div /') in coding conventions

2012-08-28 Thread Niklas Laxström
On 28 August 2012 02:26, Daniel Friesen dan...@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_elements var $hello = $('div').text( 'Hello' ); // Not 'div/' // Not 'div/div'

Re: [Wikitech-l] $( 'div' ) vs. $( 'div /') in coding conventions (and methods for building DOMs with jQuery)

2012-08-28 Thread Trevor Parscal
Rob is correct that using addClass is the preferable way to go for classes, and attr is the preferable way to go for other attributes. They are both are safe since they use setAttribute internally which escapes the values. - Trevor On Tue, Aug 28, 2012 at 10:29 AM, Rob Lanphier

Re: [Wikitech-l] $( 'div' ) vs. $( 'div /') in coding conventions (and methods for building DOMs with jQuery)

2012-08-28 Thread Mark Holmquist
On 12-08-28 10:40 AM, Trevor Parscal wrote: Rob is correct that using addClass is the preferable way to go for classes, and attr is the preferable way to go for other attributes. They are both are safe since they use setAttribute internally which escapes the values. In creating elements,

Re: [Wikitech-l] $( 'div' ) vs. $( 'div /') in coding conventions (and methods for building DOMs with jQuery)

2012-08-28 Thread Trevor Parscal
jQuery internally maps 'tagName' to document.createElement( 'tagName' ). This is a feature, and is used throughout jQuery internally. It's not very well documented as such, but Timo is adding it to the documentation as to resolve the confusion around this. $( 'div' ) is a shortcut added to jQuery

Re: [Wikitech-l] $( 'div' ) vs. $( 'div /') in coding conventions (and methods for building DOMs with jQuery)

2012-08-28 Thread Ryan Kaldari
On 8/28/12 10:52 AM, Trevor Parscal wrote: jQuery internally maps 'tagName' to document.createElement( 'tagName' ). This is a feature, and is used throughout jQuery internally. It's not very well documented as such, but Timo is adding it to the documentation as to resolve the confusion around

Re: [Wikitech-l] $( 'div' ) vs. $( 'div /') in coding conventions (and methods for building DOMs with jQuery)

2012-08-28 Thread Rob Moen
Timo where are you ? +1 .addClass as it directly manipulates the .className property. On Aug 28, 2012, at 10:52 AM, Trevor Parscal wrote: jQuery internally maps 'tagName' to document.createElement( 'tagName' ). This is a feature, and is used throughout jQuery internally. It's not very

Re: [Wikitech-l] $( 'div' ) vs. $( 'div /') in coding conventions (and methods for building DOMs with jQuery)

2012-08-28 Thread Ryan Kaldari
Unfortunately, our resident Javascript master is eating dinner :) Ryan Kaldari On 8/28/12 11:00 AM, Rob Moen wrote: Timo where are you ? +1 .addClass as it directly manipulates the .className property. On Aug 28, 2012, at 10:52 AM, Trevor Parscal wrote: jQuery internally maps 'tagName' to

Re: [Wikitech-l] $( 'div' ) vs. $( 'div /') in coding conventions (and methods for building DOMs with jQuery)

2012-08-28 Thread Rob Moen
On Aug 28, 2012, at 10:52 AM, Trevor Parscal wrote: jQuery internally maps 'tagName' to document.createElement( 'tagName' ). This is a feature, and is used throughout jQuery internally. It's not very well documented as such, but Timo is adding it to the documentation as to resolve the

Re: [Wikitech-l] $( 'div' ) vs. $( 'div /') in coding conventions (and methods for building DOMs with jQuery)

2012-08-28 Thread Trevor Parscal
On Tue, Aug 28, 2012 at 11:00 AM, Ryan Kaldari rkald...@wikimedia.orgwrote: In that case, perhaps we should just say that all of the options are fine: $( 'div' ) $( 'div/' ) $( 'div/div' ) but emphasize not to use attributes in the tag creation. Unless you are creating an input or a

Re: [Wikitech-l] $( 'div' ) vs. $( 'div /') in coding conventions (and methods for building DOMs with jQuery)

2012-08-28 Thread Daniel Friesen
On Tue, 28 Aug 2012 11:12:22 -0700, Rob Moen rm...@wikimedia.org wrote: On Aug 28, 2012, at 10:52 AM, Trevor Parscal wrote: jQuery internally maps 'tagName' to document.createElement( 'tagName' ). This is a feature, and is used throughout jQuery internally. It's not very well documented

Re: [Wikitech-l] $( 'div' ) vs. $( 'div /') in coding conventions (and methods for building DOMs with jQuery)

2012-08-28 Thread Trevor Parscal
On Tue, Aug 28, 2012 at 11:15 AM, Daniel Friesen dan...@nadir-seen-fire.com wrote: That's an unintentional side effect. jQuery does not officially support $( 'div' ) without a closing /div or /. And yet they use it themselves internally? As I mentioned, Timo is a jQuery maintainer and said

Re: [Wikitech-l] $( 'div' ) vs. $( 'div /') in coding conventions (and methods for building DOMs with jQuery)

2012-08-28 Thread Krinkle
Okay, sorry for being away for 30 minutes while I enjoyed dinner. Someone[1] pointed me to this thread and suggested I chime in, so here I go. On Aug 28, 2012, at 2:50 AM, Daniel Friesen dan...@nadir-seen-fire.com wrote: Either way $( 'div' ) is NOT something officially supported by jQuery

Re: [Wikitech-l] $( 'div' ) vs. $( 'div /') in coding conventions (and methods for building DOMs with jQuery)

2012-08-28 Thread Trevor Parscal
+1 Thank you for grounding this conversation in reality. - Trevor On Tue, Aug 28, 2012 at 12:18 PM, Krinkle krinklem...@gmail.com wrote: Okay, sorry for being away for 30 minutes while I enjoyed dinner. Someone[1] pointed me to this thread and suggested I chime in, so here I go. On Aug

Re: [Wikitech-l] $( 'div' ) vs. $( 'div /') in coding conventions

2012-08-28 Thread Daniel Friesen
On Tue, 28 Aug 2012 10:40:23 -0700, Niklas Laxström niklas.laxst...@gmail.com wrote: On 28 August 2012 02:26, Daniel Friesen dan...@nadir-seen-fire.com wrote: I ran into our coding conventions for creating elements in JS:

Re: [Wikitech-l] $( 'div' ) vs. $( 'div /') in coding conventions (and methods for building DOMs with jQuery)

2012-08-28 Thread Helder .
On Tue, Aug 28, 2012 at 4:18 PM, Krinkle krinklem...@gmail.com wrote: Moreover, aside from the performance and security, there's another important factor to take into account. And that is the fact that IDs can contain characters that have special meaning in CSS selectors (such as dots).

[Wikitech-l] $( 'div' ) vs. $( 'div /') in coding conventions

2012-08-27 Thread Daniel Friesen
I ran into our coding conventions for creating elements in JS: https://www.mediawiki.org/wiki/Manual:Coding_conventions/JavaScript#Creating_elements var $hello = $('div').text( 'Hello' ); // Not 'div/' // Not 'div/div' This looks like some really bad advice. This dates back to an issue I ran

Re: [Wikitech-l] $( 'div' ) vs. $( 'div /') in coding conventions (and methods for building DOMs with jQuery)

2012-08-27 Thread Mark Holmquist
Hence, I think we should change our coding conventions to always use `$( 'div /' )`. +1 for valid XHTML. Considering that bytes are cheap and validity is good, this seems like a good idea. I also tried to get an answer about the better between $( 'div class=a-class /' ) and $( 'div /'

Re: [Wikitech-l] $( 'div' ) vs. $( 'div /') in coding conventions (and methods for building DOMs with jQuery)

2012-08-27 Thread Trevor Parscal
$( 'div' ) is the way to go. - Trevor On Mon, Aug 27, 2012 at 4:37 PM, Mark Holmquist mtrac...@member.fsf.orgwrote: Hence, I think we should change our coding conventions to always use `$( 'div /' )`. +1 for valid XHTML. Considering that bytes are cheap and validity is good, this seems

Re: [Wikitech-l] $( 'div' ) vs. $( 'div /') in coding conventions (and methods for building DOMs with jQuery)

2012-08-27 Thread Ori Livneh
On Monday, August 27, 2012 at 4:40 PM, Trevor Parscal wrote: $( 'div' ) is the way to go. Yeah. Mark Pilgrim's overview of the sordid history of XHTML is useful background: http://diveintohtml5.info/past.html -- Ori Livneh o...@wikimedia.org

Re: [Wikitech-l] $( 'div' ) vs. $( 'div /') in coding conventions (and methods for building DOMs with jQuery)

2012-08-27 Thread Daniel Friesen
On Mon, 27 Aug 2012 16:57:52 -0700, Ori Livneh o...@wikimedia.org wrote: On Monday, August 27, 2012 at 4:40 PM, Trevor Parscal wrote: $( 'div' ) is the way to go. Yeah. Mark Pilgrim's overview of the sordid history of XHTML is useful background: http://diveintohtml5.info/past.html --

Re: [Wikitech-l] $( 'div' ) vs. $( 'div /') in coding conventions (and methods for building DOMs with jQuery)

2012-08-27 Thread Ori Livneh
On Monday, August 27, 2012 at 5:50 PM, Daniel Friesen wrote: If you don't like the XHTML-ish shortcut that jQuery provides, then our coding conventions should be to use `$( 'div/div' );`. Either way $( 'div' ) is NOT something officially supported by jQuery and makes it easy for

Re: [Wikitech-l] $( 'div' ) vs. $( 'div /') in coding conventions

2012-08-27 Thread Tim Starling
On 28/08/12 09:26, Daniel Friesen wrote: jQuery does special case attribute-less $( 'div /' ) but this is a performance enhancement. The fact that $( 'div' ) does not break in IE7/IE8 is an unintentional side effect of jQuery's lazy support of special cases like $( 'img' ) where the tag is

Re: [Wikitech-l] $( 'div' ) vs. $( 'div /') in coding conventions (and methods for building DOMs with jQuery)

2012-08-27 Thread Chris Steipp
On Mon, Aug 27, 2012 at 4:37 PM, Mark Holmquist mtrac...@member.fsf.org wrote: I also tried to get an answer about the better between $( 'div class=a-class /' ) and $( 'div /' ).addClass( 'a-class' ), but apparently there's little difference. At least when creating dynamic interfaces, I'd like