[jQuery] Re: Creating custom attributes in html

2009-04-17 Thread RobG
On Apr 17, 3:34 pm, RobG rg...@iinet.net.au wrote: [...] OK, here is a dead basic proof of concept.  Of course it is nowhere near production code, but I think you can see where it's going.  I would wrap the entire thing in the module pattern, but I've just used basic globals at this stage.  

[jQuery] Re: Creating custom attributes in html

2009-04-17 Thread roger
Josh, Since you aren't creating nodes, why not wait until after you insert the string of html onto the page, at which point you will have access to those nodes, so you can loop through them and set all of the corresponding properties on them using .data() or just the usual

[jQuery] Re: Creating custom attributes in html

2009-04-17 Thread dhtml
On Apr 14, 3:34 pm, Ricardo ricardob...@gmail.com wrote: If you insert these attributes server-side, the page will not validate and might trigger quirks mode in the browser. Which browser? Thanks, Garrett

[jQuery] Re: Creating custom attributes in html

2009-04-16 Thread Kean
I see a lot of string concatenations. Use this instead. var str=[]; for(var i=0; i200; i++) str.push('table id=a_'+ i + '/table'); $(str.join('')).appendTo('div'); Also, from a performance standpoint, it's much faster to use W3c DOM methods to create nodes than using the innerHTML method to

[jQuery] Re: Creating custom attributes in html

2009-04-16 Thread Josh Powell
@all - So far, the only reasons I've heard not to add custom attributes are 1) Dogma, 2) May cause quirks mode. In my mind, the benefits gained by using custom attributes: less code, simplicity, and clarity, far outweigh these two reasons not to do it. @Jack K - Thanks for the links :). I

[jQuery] Re: Creating custom attributes in html

2009-04-16 Thread RobG
On Apr 16, 7:53 pm, Josh Powell seas...@gmail.com wrote: @all - So far, the only reasons I've heard not to add custom attributes are 1) Dogma, Dogma: a religious doctrine that is proclaimed as true without proof URL:

[jQuery] Re: Creating custom attributes in html

2009-04-16 Thread Ricardo
Josh, I have to agree with Rob on the class thing. It's really not meant specifically for presentation, it just happens to be one of the most practical (and fully supported) selectors in CSS. There's no problem in using jquery.metadata to store data in it, it's valid HTML (yes, quirks mode can

[jQuery] Re: Creating custom attributes in html

2009-04-16 Thread Kean
@Josh Powell - string concatenation is plenty fast 99% of the time and a lot more readable. Yes string concatenation is more readable and 99% faster for normal usage. But looping and concatenate a huge chunk in this particular case is slower. Reason: every + between 2 strings returns a new string

[jQuery] Re: Creating custom attributes in html

2009-04-16 Thread Josh Powell
@all - thanks for all the comments. Love the heated discussion. @RobG - can you code up some example code as to how you would solve the same problem I presented code for? And while it is off topic...can you provide the code you used to run the benchmarking? I'm not challenging your results,

[jQuery] Re: Creating custom attributes in html

2009-04-16 Thread RobG
On Apr 17, 10:08 am, Josh Powell seas...@gmail.com wrote: @all - thanks for all the comments.  Love the heated discussion. @RobG - can you code up some example code as to how you would solve the same problem I presented code for? OK, here is a dead basic proof of concept. Of course it is

[jQuery] Re: Creating custom attributes in html

2009-04-15 Thread Karl Swedberg
On Apr 14, 2009, at 6:34 PM, Ricardo wrote: If you insert these attributes server-side, the page will not validate and might trigger quirks mode in the browser. If you are adding them after load, there's no harm in it, but I bet using data() would be faster for lots of elements. I was

[jQuery] Re: Creating custom attributes in html

2009-04-15 Thread JBeckton
I was using custom attributes, I just discovered that when using live () to bind events to HTML elements coming in via AJAX would mysteriously stop working. I searched around the bugs DB and found that it was the custom attributes I was using to select the elements to bind to that was causing

[jQuery] Re: Creating custom attributes in html

2009-04-15 Thread mkmanning
This is not quite to the point of discussing the merits per se, but still germane I think. RobG pointed out that you're using the name attribute in a div, which isn't valid. It's also not valid in a td, but obviously that only matters if validation is important to you (which is a totally separate

[jQuery] Re: Creating custom attributes in html

2009-04-15 Thread Josh Powell
@all - thank you for your comments. What I've learned is 1) custom attributes are referred to as DOM Expandos, 2) they can cause IE to go into strict mode, 3) Developers often override the class or id of an element to store data instead of using a DOM Expando, and 4) There is a bug in jQuery

[jQuery] Re: Creating custom attributes in html

2009-04-15 Thread Jack Killpatrick
Nice summary, thanks. Here's some more potential food for thought: http://ejohn.org/blog/html-5-data-attributes/ http://www.1729.com/blog/HtmlAnnotations.html FWIW, in general I've steered away from using custom attributes and have generally used id=name_123 (often), class with data inside

[jQuery] Re: Creating custom attributes in html

2009-04-15 Thread RobG
On Apr 16, 10:15 am, Josh Powell seas...@gmail.com wrote: @all - thank you for your comments. What I've learned is 1) custom attributes are referred to as DOM Expandos, No, expandos are custom DOM object *properties*, HTML elements have attributes. URL:

[jQuery] Re: Creating custom attributes in html

2009-04-14 Thread Ricardo
If you insert these attributes server-side, the page will not validate and might trigger quirks mode in the browser. If you are adding them after load, there's no harm in it, but I bet using data() would be faster for lots of elements. On Apr 14, 2:56 pm, seasoup seas...@gmail.com wrote: I was

[jQuery] Re: Creating custom attributes in html

2009-04-14 Thread Josh Powell
I cannot use .data() as I do not have a node. Creating a node for every td creates impossibly excessive append time. One one page I shortened the time to append for 500 table rows from 29,000ms to 900ms. Good to know about the potential for triggering quirks mode though, thanks. Josh Powell

[jQuery] Re: Creating custom attributes in html

2009-04-14 Thread James
You might want to check out the Metadata plugin: http://plugins.jquery.com/project/metadata It'll let you get data in the CLASS (and other custom) attribute so your HTML can technically remain valid (I think). Personally, I try to keep my code as valid as possible to hopefully avoid quirks mode

[jQuery] Re: Creating custom attributes in html

2009-04-14 Thread RobG
On Apr 15, 8:41 am, Josh Powell seas...@gmail.com wrote:  Good to know about the potential for triggering quirks mode though, thanks. You are already using invalid markup by adding a name attribute to a div element. Have you considered storing the data in the class attribute, then use DOM