Get top style from dynamic content
I'm trying to get a top style that is being applied to dynamic added content and assign to an image.
I've built a function w/ Timeout to check if it's parent exists and then get the css(top) value.
It's firing now, but I can't assign the top style to the image margins.
- function addGalleryDone() {
- var emarck = $('.justified-gallery .pro').first().find('img').css('margin-left');
- if (($('.justified-gallery').length) && (emarck != '0px')) {
- console.log('Galleryload Done');
- $('a').each(function() {
- var jmari = $(this).css('top');
- var jmar = jmari + '!important';
- console.log('JustifiedMargin: ' + jmar); // 3px !important
- $(this).find('img').css({'margin-top': ' + jmar + ', 'margin-left': ' + jmar + '});
- });
- }
- else {setTimeout(addGalleryDone, 300);}
- }
- addGalleryDone();
HTML when it's done:
- <div class ="justified-gallery">
- <span class="pro">
- <a href="...." style="top: 3px.....">
- <img style="margin-left: -171.5px; .....">
- </span>
- </div>