You're better off giving them the same class, so you can loop through them as an array in jQuery:
<div class="bar" id="q1">21</div>
<div class="bar" id="q2">40</div>
Then:
var bars = $('.bar')
- this gives you your collection
You need to determine which one is the biggest:
var maxBar = 0
for(var x=0;x<bars.length;x++) {
if(parseInt($(bars[x]).text())>maxBar) {
maxBar = parseInt($(bars[x]).text())
}
}
From here, adjust the size of the bars in proportion to the largest:
for(var x=0;x<bars.length;x++) {
mySize = parseInt($(bars[x]).text())
$(bars[x]).css('width', parseInt(mySize/maxBar)*100)+'%')
}
Wrap your bars in a DIV and give it a width as desired.