javascript - How to apply this method to all future matching elements as well? -
the following javascript/jquery snippet applies css matchicng elements in dom.
$('.centeredbyjquery').each(function(){ $(this).css({'margin-left': -parseint($(this).css('width'))/2, 'left':'50%', 'margin-top': -parseint($(this).css('height'))/2, 'top':'50%'}); })
how apply method future matching elements ?
you can't.. way using interval:
setinterval(function(){ $('.centeredbyjquery').each(function(){ $(this).css({'margin-left': -parseint($(this).css('width'))/2, 'left':'50%', 'margin-top': -parseint($(this).css('height'))/2, 'top':'50%'}); }) },1000);
but terrible idea..
if know when new element inserted, can call function center element.
Comments
Post a Comment