Checking for class name in $.each()

Hello, all,

I’ve got some code that will serializeArray() form data, in order to put it all into a single JSON object for saving to localStorage. I’d like to check to see if a form element has a particular class (those with should be included; those without should not.) Here’s what I have, so far (pseudo code).

lsData = {};
$.each(
  $('#formName').serializeArray(), function(index,field){
    lsData[field.name] = field.value;
});
storage.setItem('procOpp',JSON.stringify(lsData));

I’ve tried if($(this).hasClass('l_s')), but it always shows false.

How can I check to see if a certain class is applied to an element in this fashion?

V/r,

:slight_smile:

I fingered it out. :smile:

if($('#' + field.name).hasClass('l_s')){
  // do whatever
}

V/r,

:slight_smile:

2 Likes

:open_mouth:

Don’t forget to wash finger after that :smile:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.