I was just looking at some code that I wrote a little over two months ago.
It occurred to me that the code, as it currently exists, isn’t nearly as efficient as it could be. But I’m not sure how to do what I think I need to do.
Brief description: the code in question is for saving a user’s contact information in localStorage. Quite simply, I’m using serializeArray() to put all form elements into an array, looping that, checking for a specific class, and if the element has that class, add it to the string that will be stored in localStorage.
What I would LIKE to do is get only those elements with that specific class; instead of serializing the whole form, I’d like to serialize only those fields with that class.
What I’m using, now is:
$.each($('#formID').serializeArray(), function(index,field){
//.. do stuff
});
storage.setItem('contact',JSON.stringify(lsData));
Is there a way to specify that the only items to serialize are the inputs with a certain class??