var labelMap = { 'id_q': '

Search:

', 'id_models_0': 'You could also narrow your search. Select a category.' } $(function() { for (var i in labelMap) { if (labelMap.hasOwnProperty(i)) { if ($('label[for=' + i + ']').length > 0) { $('label[for=' + i + ']').eq(0).addClass(i).html(labelMap[i]); } } } });