jQuery Code Snippets (from jMe)

Posted on Wednesday 6 December 2006 - Popularity: unranked

jquery code snippets

Just a few jQuery code snippets I’m using on the jMe feed aggregator that may be useful to some:

$("#mydiv").children().each(function(i){
    if (i > 10){
        $(this).remove();
    }
});

This one removes all childrens from #mydiv with a count greater than ten. Useful if you want to limit the number of childrens inside an element where you dynamicaly add new elements. jMe is using this one for the spy feature.

$(".mydesc a").each(function(){
    this.target = "_blank";
});

The description of feed items can contain links, not all of them use ‘_blank’, so it can happen that they open in the same window. To solve this problem, the above code changes all links inside elements with a class ‘mydesc’ to open in a new blank window. Normaly to do that you would have to use regular expressions, not so with the help of jQuery.

$(‘a’).click(function() {
    this.blur();
});

I really don’t like those dotted rectangles that get put around links you click, especially if those links just trigger some JavaScript and not a new page. The above snippet takes those ugly attention grabbers away. Don’t forget to run this code everytime you dynamicaly add new links.

$("#myitem").insertBefore($("#myitem").prev());

This little snippet here moves an element one step up in a set of elements. This is more or less what I use in jMe on the up button of previously selected elements.

$("#myitem").insertAfter($("#myitem").next());

Basicaly the same as above, just in the other direction (one step down).

Fredi

Bookmark options for this entry: Add to del.icio.us | Add to Furl | Add to Spurl

Comments are closed.






Times when I have posted during the last month



(c) 2005 by Fredi Bach


New: Feed Aggregator


New: Projects Site


New: Weblog







To gain maximum knowledge of the network world, go for some online courses like N10-003 and SY0-101. You will easily be able to play with the wireless cable concept. It will not be hard to install a computer software without any instructions. Not only this, you will also be able to work on a remote pc software. Sounds too good? Bet it is!







Recently Played Songs

more ...



Recently Used Apps
- - -
On my G5
- - -
AutomountMaker
- - -
Clutter
- - -
Cyberduck
- - -
Firefox
- - -
Flash 8
- - -
Microsoft Word
- - -
Systemeinstellungen
- - -
TextEdit
- - -
TextMate
- - -
Yummy FTP
- - -
On my MacBook
- - -
Adobe Photoshop CS3
- - -
Firefox
- - -
Google Earth
- - -
iTunes
- - -
Overflow
- - -
QuickTime Player
- - -
Systemeinstellungen
- - -
TextMate
- - -
Vorschau
- - -
Yummy FTP





Give me a 10!

Computers Blog Top Sites





Recent Comments

- - -
startoy
(A list of the best free Ajax web apps):ajaxflakes - Read all about the...
- - -
michelle
(The future of the iPod):can you tell me my code...
- - -
Sohbet
(Everything tagged in TagWorld):Thanks for the tips Dan, a...
- - -
pascal
(Macworld Keynote 2006 ... live updates):i lover mac compuetre
- - -
toothpick_tp
(Am I unhealthy because I run a blog?):Never mind! There are a lot...
- - -
Sohbet
(Everything tagged in TagWorld):I think the idea of writing...
- - -
Mcgill
(Flip4Mac, free download!):QuickTime can play any file format...
- - -
freda
(OS X Code for ya!):Try Mac Cleanse http://www.qweas.com/download/antivirus/internet_tracks_cleanup/mac_cleanse.htm
- - -
Enlargement
(Flip4Mac, free download!):First of all I d'like to...
- - -
pyrethrum
(WordPress plugin "wikicache" preview):Hi,very colorful article in this nice...