KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Is there a way to check an elements parents and find the first one that has a CSS background set and then return that background value? Something like: var background = $('element').parents().has(css('background')); UPDATE: This is the code I'm now using: jQuery.fn.getBg = function(){ var newBackground = this.parents().filter(function() { return $(this).css('background-color').length > 0; }).eq(0).css('background-color'); $(this).css('background-color',newBackground); console.log("new background is: "+newBackground); };
Tags (comma-separated)
Save Edits
Cancel