//See License At: http://www.quickcapt.com/license.html function replace_image(image_ref, desired_class, set_title_to_alt){ //alert(document.getElementById('test1').alt) //document.getElementById('test1').alt = 'One small step'; //Create a wrapper Div var newdiv = document.createElement('div'); newdiv.className = desired_class; //Set div width equal to image width newdiv.style.width = image_ref.width; //Put the div in... Above the image image_ref.parentNode.replaceChild(newdiv, image_ref); //Put the image in the div newdiv.appendChild(image_ref); if (set_title_to_alt){ image_ref.title = image_ref.alt; } //Put the text in after the image newdiv.appendChild(document.createTextNode(image_ref.alt)); } function check_class(image_ref, class_name){ if (image_ref.className == class_name){ return true; } else { return false; } } function run_me(){ var dont_check_class = true; var set_title_to_alt = true; var desired_class = 'image_border'; var all_page_images = document.getElementsByTagName('img'); var image_refs = new Array(all_page_images.length); //Because Images will get replaced on the page, we can't reference them directly... Store the references. //If you've got a better way to solve this problem, I would love to hear it! for (var j = 0; j < all_page_images.length; j++){ image_refs[j] = all_page_images[j]; } //Begin Main Loop for (var i = 0; i < image_refs.length; i++){ if (dont_check_class || check_class(image_refs[i], 'mee')){ replace_image(image_refs[i], desired_class, set_title_to_alt); } } }