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

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -