Skip to content

Instantly share code, notes, and snippets.

@gabemartinez
Last active November 11, 2015 21:30
Show Gist options
  • Save gabemartinez/4286489fd44259303e6a to your computer and use it in GitHub Desktop.
Save gabemartinez/4286489fd44259303e6a to your computer and use it in GitHub Desktop.
Pulling IDs and Custom Attribute Values Based on Selector, then looping and setting css after DOM is ready - jQuery
(function($){
$(document).ready(function(){
//setting class for all full bg image co paragraphs
$('.full-background-image-callout').parent().parent().parent().parent().parent().parent().parent().parent().parent().addClass('full-background-image-callout-background');
//total amount of full bg image co paragraphs in this document
var amountoffullbackgroundparagraphs = $('.full-background-image-callout-background').length;
console.log(amountoffullbackgroundparagraphs);
var workwiththeseids = $('.full-background-image-callout-background').map(function() { return this.id; }).get();
//console.log(workwiththeseids);
var workwiththesebgs = $('.full-background-image-callout').map(function () { return $(this).attr("needthisbg"); });
//console.log(workwiththesebgs);
for (x = 0; x < amountoffullbackgroundparagraphs; x++) {
//console.log(workwiththeseids[x]);
//console.log(backgroundgraphics[x]);
$('#' + workwiththeseids[x]).css('background-image', 'url(' + workwiththesebgs[x] + ')');
}
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment