I’m mapping values that I receive from an ajax call. It works pretty well, but it is still not fast enough in ie7 (I’m getting a slow script warning).
I can’t figure out any way to make this faster. I’ve tried using native javascript functions as well, but the speed improvement was negligible. Do you guys have any ideas?
var $audit = $('#audit');
$.each(data, function (i, val) {
if (val != null && val !== '0') {
$audit.find('input[type="checkbox"].' + i).attr('checked', val == 1);
$audit.find('input[type="text"].' + i).val(val);
$audit.find('select.' + i).val(val);
}
});
Some psuedo-html:
<div id="audit">
<input type="text" class="foo1" />
<input type="checkbox" class="foo2" />
<select class="foo3">
<option value="1">1</option>
</select>
</div>
I dont know if it will help that much but you could cache your inputs + select and just filter that instead of finding the “same” element over and over again and just filter the specific element in a much smaller collection: