Subject: Samsung 50&quot; for as low as $65.26.

From: Black Friday Cyber Blowout <[email-masked]>
Date: Fri, 28 Nov 2014 13:30:52 -0800

BLACK FRIDAY CYBER BLOWOUT

** One Day Only While Supplies Lasts **

** Electronics are 90% OFF **

View Hottest Sellers that Just Shipped

Cant See the Image Below? Click Here to View

HappyBidDay | 113 Barksdale Professional Center | Newark | DE | 19711

Unsubscribe Here

Could it not be stored in an array? I mean instead of the hidden elements you store the values in an array. Alex Apr 15 '13 at 7:01

1

The interviewer might just wanted to see your reaction when he/she criticises you. Uooo Apr 15 '13 at 7:13

I did all that just in 30 minutes, And even on his criticize, I was confident for what I did. Actually where I applied was one well known IT company. Rajan Rawal Apr 15 '13 at 7:18

8

I really don't understand SO sometimes. This is too localized and not constructive. This is a code at best, and certainly not worth the 19 points. Ohgodwhy Apr 15 '13 at 7:33

@Ohgodwhy, you are true. But when all these happened to me, my confidence went down. So wanted to know best approach. And it I am not wrong, SO is also where you can get best approach. Rajan Rawal Apr 15 '13 at 7:46

Fair enough, Rajan. Ohgodwhy Apr 15 '13 at 7:47

@Ohgodwhy, I just want no one to repeat the mistake if I did any so... hope you aer agree. Rajan Rawal Apr 15 '13 at 7:52

As it closed by sake of code , just want to tell i strictly follow code indentation and web standards considering php, html, javascript and even in CSS. Thank you Rajan Rawal Apr 19 '13 at 4:59

add a comment

8 Answers

activeoldestvotes

up vote

6

down vote

accepted

Another approach for client-side is to keep a list of objects separately and only store the reference to each item inside a property of your DOM element. This approach is very similar to what jQuery's .fn.data() provides and has these advantages:

You don't have to serialize anything, the data stays in its native format; it should be said that you could have achieved this by adding a property as well.

All your data is kept in one place instead of scattered around in the DOM.

This is an example implementation:

(function(ns) {

var entries = {},

entryId = 1;

ns.Entries = {

addEntry: function(data) {

entries[entryId] = data;

return entryId++;

},

getEntryById: function(id) {

return entries[id] || null;

}

};

}(this));

Calling Entries.addEntry returns an identifier that you can store in one of the DOM element's properties:

tr.entryId = Entries.addEntry(data);

Later you can use that entryId property to find the corresponding data in the entry list and use it.