 <p>Here's what I would do with what you've given</p> <pre><code>$('span.[class^="cell_"]').each(function(i,v){ // loop through each span with class that starts with cell_ var num = +$(v).attr('class').split('_')[1]; // get the number from the class $(v).css('left',(num * 10) + 'px') // use it to get the px }); </code></pre>