I’m trying to integrate the Lightbox plugin into a clients CMS. This should be easy, all I need to do is find the <a> surrounding thumbnail images (the CMS automatically gives these the class ‘gs_image_link’) and use Javascript to add the rel=‘lightbox’ attribute that triggers the Lightbox plugin.
I have the following being linked to in a seperate .js file:
window.onload = function() {
addRelFunction();
}
function addRelFunction() {
// get all <a> tags
var allLinks = document.getElementsByTagName(“a”);
// Cycle through all <a> tags
for (var i=0; i<allLinks.length; i++) {
// get the ‘class’ of the current <a> tag
var title_text = allLinks[i].getAttribute(“class”);
// if the current <a> tag has a class of ‘gs_image_link’, add rel=‘lightbox’
if (title_text == “gs_image_link”) {
allLinks[i].setAttribute(“rel”, “lightbox”);
// pop up alert to let me know it has added the rel
alert(allLinks[i].getAttribute(“rel”));
};
};
};
My code so far isn’t doing what I expect, on a page with 2 '<a class=“gs_image_link”>'s I get two pop up alerts telling me they now have a rel of ‘lightbox’ but when viewing the source the rel has not been added.
Any help on where I’m going wrong?