Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add border to images

I'm totally new to JS. I'm trying to make me a bookmarklet that finds all images on a web page and adds a colorful border to them. Then, by clicking on an image I'd like to attach the image path. This is what I've got so far:

javascript:
for (var i= document.links.length; i-->0;) {
    if (document.links[i].getElementsByTagName('img').length!=0) {
        document.links[i].onclick= function() {
           window.open("http://www.example.com/whatever?imgsrc=" + this.src + "");
        };
    }
}

How can I add a border to the images?

Thanks, Bob

like image 270
Michael Avatar asked Mar 01 '11 23:03

Michael


1 Answers

Try this code:

javascript:for(i=0;i<document.getElementsByTagName('img').length;i++){var imgTag=document.getElementsByTagName('img')[i];imgTag.style.border='2px solid #E8272C';imgTag.onclick=function(){return !window.open(this.src)};}void(0)

Friendly formatted view:

javascript:
for(i=0;i<document.getElementsByTagName('img').length;i++){
    var imgTag=document.getElementsByTagName('img')[i];
    imgTag.style.border='2px solid #E8272C';
    imgTag.onclick=function(){
        return !window.open(this.src);
    }
}void(0)
like image 188
ahgood Avatar answered Sep 24 '22 22:09

ahgood