javascript - How to retrieve .length of numerous elements with a particular class using jQuery? -
yo guys, problem follows: on website i'm working there numerous boxes, each of has little area in corner supposed count users when website goes live. thus, test i've used id in markup accommodating number:
<span id="usercount">612</span>
with following lines of simple jquery:
var users = $('#usercount').text().length; if (users >= 4) { $('#usercount').css('font-size','12px'); $('#usercount').css('margin-left','7px'); }
as see, if number has 4 or more symbols gets smaller , aligned inside area. since there should numerous boxes on website, i've changed id="usercount" class="usercount" , it's not working longer. understand there should loop retrieving same piece of data every element class of "usercount" can't figure out how put down competently proper syntax. realize it's simple operation, i'm new js , appreciate assistance. lot!
you can use filter
method:
$('.usercount').filter(function() { return $(this).text().length >= 4; }).css({ 'font-size': '12px', 'margin-left': '7px' });
Comments
Post a Comment