Last active
November 11, 2015 21:30
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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