DZone 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

Snippets has posted 5883 posts at DZone. View Full User Profile

Easily Get A Single Element With JQuery

  • submit to reddit
        While jQuery is a great help, a lot of times I just need to grab a single element. It's a real PITA to have to write $('#mydiv').get(0) all the time, so here's a solution:

$.first = function(a, b) {return $(a, b).get(0)};


Snippets Manager replied on Mon, 2012/05/07 - 1:25pm

Depending on such 3rd-party libraries to make simple codes is the worse thing a person can do :(