Created
April 25, 2013 02:54
-
-
Save ScotterC/5457198 to your computer and use it in GitHub Desktop.
Vanilla javascript method to find all imgs in html, check the first and then second parent if it's a p tag and add text-align center
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() { | |
var first_parent, i, img, imgs, second_parent; | |
imgs = document.getElementsByTagName("img"); | |
img = void 0; | |
i = 0; | |
while (i < imgs.length) { | |
img = imgs[i]; | |
first_parent = img.parentNode; | |
if (first_parent.localName === "p") { | |
first_parent.style.cssText = "text-align:center"; | |
} else { | |
second_parent = first_parent.parentNode; | |
if (second_parent.localName === "p") { | |
second_parent.style.cssText = "text-align:center"; | |
} | |
} | |
i++; | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment