Skip to Content

JSON

Parse class values: Retrieving custom meta data from an HTML element's class name

The problem

I had HTML that had class information on each object that signified how deeply it was indented (e.g. "indent-5"). I needed to use the value of the indent to make various comparisons in another. To solve this problem I created a simple utility function.

NOTE: All functions were written with a dependancy on jQuery.

Original

I created an array of the object's classes by splitting the string at the instance of a space. I made the assumption that the indent class would always be the first and accessed the first element of the object class array I created.

Syndicate content