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 = {};
  $('#formName').serializeArray(), function(index,field){
    lsData[] = field.value;

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?



I fingered it out. :smile:

if($('#' +'l_s')){
  // do whatever





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.