Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

About this user

« Newer Snippets
Older Snippets »
4 total  XML / RSS feed 

Select spacer images

Regular expression to select image tags with images whose names end in spacer.

<img src="[\w\/\-\_]*spacer.[jpeg|jpg|gif|png]+[^>]*/?>

Select inline styles

Selects inline styles. I purposely excluded quotation marks from the character set because they cause the expression to select attributes of other tags on the same line.

style="[\s\d\w\.\-\:\;]+"


Edit: Here's a shorter way of accomplishing the same thing:

style="[^"']+"


It's probably worth adding a space before the expression to make sure that you don't leave in unnecessary spaces in the tag and to avoid selecting things that are not styles, such as the bold part of



Select all font tags

Regular expression to select all font tags in a HTML document.

?(FONT|font)[^>]*>

Resize image to fit container

Resizes an image to fit into its container, depending on whether the width or height is longer, yet keeping the aspect ratio. Copied from a comment on sitepoint.com.

ffunction resizeImgOO(el) 
{ 
        function imgRatio()
        { 
                return (el.height / el.width); 
        } 
        function holderRatio()
        { 
                return (el.offsetParent.offsetHeight / el.offsetParent.offsetWidth); 
        } 
        function fitToContainer()
        { 
                if(imgRatio>holderRatio) 
                { 
                        el.height = el.offsetParent.offsetHeight; 
                } 
                else 
                { 
                        el.width = el.offsetParent.offsetWidth;   
                } 
        }
        
        this.imgRatio = imgRatio; 
        this.holderRatio = holderRatio; 
        this.resize = fitToContainer; 
}
var img = new resizeImgOO(document.getElementById('yourImgId'));
img.resize();
« Newer Snippets
Older Snippets »
4 total  XML / RSS feed