Alpha
Share and Organize Code
login register
HotNewTop
F.A.Q.
1. To begin adding code first register.
2. Create your own tags for code that you add.
3. To see your own code click Me, to see all code click Everyone, or filter by people rob.
4. To follow a user, click on their username, rob and hit follow.
5. Add other code to your library by clicking the
button near the code titles (note that you can not edit these codes).
6. To create a copy of a code that you can edit use fork.
7. If you can't find your code, double check your filter settings as you can filter by Category, User and Tag simultaneously.
8. Add comments to a code by clicking on it's title or the comments link underneath it.

Select Elements That Have Any Portion Within the Viewing Window (plain)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$.extend($.expr[':'],
{
    inView: function(el)
    {
        var offset = $(el).offset();

        return !(
            (offset.top > $(window).height() + $(document).scrollTop()) ||
            (offset.top + $(el).height() < $(document).scrollTop()) ||
            (offset.left > $(window).width() + $(document).scrollLeft()) ||
            (offset.left + $(el).width() < $(document).scrollLeft())
        )
    }
});

// usage
$(#container :inView")
[+] (13) more...
comments (0) flag fork

Select Elements That Have an id Attribute Specified (plain)

1
2
3
4
5
6
7
8
9
10
$.extend($.expr[':'],
{
    hasId: function(el)
    {
        return $(el).attr('id') !== undefined && $(el).attr('id') !== '';
    }
});

// usage
$("#container :hasId");
[+] (6) more...
comments (0) flag fork

Select Elements That Have the Specified Color Value in rgb(x, x, x) Format (plain)

1
2
3
4
5
6
7
8
9
10
11
$.extend($.expr[':'],
{
    color: function(el, i, m)
    {
        if(!m[3]) {return false;}
        return $(el).css('color') === m[3];
    }
});

// usage
$("#container :color(rgb(255, 0, 0))");
[+] (7) more...
comments (0) flag fork

Select Elements That Have a CSS font-weight of 700 (bold) (plain)

1
2
3
4
5
6
7
8
9
10
$.extend($.expr[':'],
{
    isBold: function(el)
    {
        return $(el).css("fontWeight") === '700';
    }
});

// usage
$("#container :isBold");
[+] (6) more...
comments (0) flag fork

Select Elements Larger Than the Specified Element (plain)

1
2
3
4
5
6
7
8
9
10
11
$.extend($.expr[':'],
{
    largerThan: function(el, i, m)
    {
        if(!m[3]) {return false;}
        return $(el).width() * $(el).height() > $(m[3]).width() * $(m[3]).height();
    }
});

// usage
$("#container :largerThan(#element)");
[+] (7) more...
comments (0) flag fork

Selects All Anchors With the Specified Target Value (plain)

1
2
3
4
5
6
7
8
9
10
11
12
13
$.extend($.expr[':'],
{
    target: function(el, i, m)
    {
        if(!m[3]) {return false;}
        return (m[3] === '_self' && ($(el).attr('target') == '' || !el.target)) || (m[3] === $(el).attr('target'));
    }
});

// usage
$("#container :target(_self)");
$("#container :target(_parent)");
$("#container :target(frameName)");
[+] (9) more...
comments (0) flag fork

Selects All Anchor Tags With a Domain Different Than the Current Domain (plain)

1
2
3
4
5
6
7
8
9
10
11
$.extend($.expr[':'],
{
    external: function(el)
    {
        if(!el.href) {return false;}
        return el.hostname && el.hostname !== window.location.hostname;
    }
});

// usage
$("#container :external");
[+] (7) more...
comments (0) flag fork

Selects all Elements to the Right of the Specified Element (plain)

1
2
3
4
5
6
7
8
9
10
11
12
13
$.extend($.expr[':'],
{
    rightOf: function(el, i, m)
    {
        var oe = $(el).offset();
        var om = $(m[3]).offset();

        return oe.left > om.left + $(m[3]).width();
    }
});

// usage
$("#container :righttOf(#element)");
[+] (9) more...
comments (0) flag fork

Selects all Elements to the Left of the Specified Element (plain)

1
2
3
4
5
6
7
8
9
10
11
12
13
$.extend($.expr[':'],
{
    leftOf: function(el, i, m)
    {
        var oe = $(el).offset();
        var om = $(m[3]).offset();

        return oe.left + $(el).width() < om.left;
    }
});

// usage
$("#container :leftOf(#element)");
[+] (9) more...
comments (0) flag fork

Select Elements With HeightGreater Than or Less Than the Specified Value (plain)

1
2
3
4
5
6
7
8
9
10
11
12
$.extend($.expr[':'],
{
    height: function(el, i, m)
    {
        if(!m[3]||!(/^(<|>)\d+$/).test(m[3])) {return false;}
        return m[3].substr(0,1) === '>' ? $(el).height() > m[3].substr(1) : $(el).height() < m[3].substr(1);
    }
});

// usage
$(".container:height(>100)");
$("#container :height(<100)");
[+] (8) more...
comments (0) flag fork

Select Elements With Width Greater Than or Less Than the Specified Value. (plain)

1
2
3
4
5
6
7
8
9
10
11
12
$.extend($.expr[':'],
{
    width: function(el, i, m)
    {
        if(!m[3]||!(/^(<|>)\d+$/).test(m[3])) {return false;}
        return m[3].substr(0,1) === '>' ? $(el).width() > m[3].substr(1) : $(el).width() < m[3].substr(1);
    }
});

// usage
$(".container:width(>100)");
$("#container :width(<100)");
[+] (8) more...
comments (0) flag fork

Check if an Element is "loaded" (plain)

1
2
3
4
5
6
7
8
$.extend($.expr[':'],
{
    loaded: function(el) { return $(el).data('loaded'); }
});

// usage
$("img").load(function(){ $(this).data("loaded", true); });
$("#container img:loaded");
[+] (4) more...
comments (1) flag fork

Load jQuery From Google With Graceful (local) Fallback (plain)

1
2
3
4
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
    window.jQuery || document.write('<script src="js/libs/jquery-1.7.1.min.js"><\/script>');
</script>
comments (0) flag fork

Capture enter key on input elements (plain)

1
2
3
4
5
6
7
$("#login_email, #login_password").keyup(function(e)
{
    var code = e.keyCode || e.which;
    e.preventDefault();

    if(code == 13) login();
});
[+] (3) more...
comments (0) flag fork