Skip to content

Instantly share code, notes, and snippets.

@lelinhtinh
Created September 15, 2014 06:22
Show Gist options
  • Save lelinhtinh/3e8a217a08388aa2002e to your computer and use it in GitHub Desktop.
Save lelinhtinh/3e8a217a08388aa2002e to your computer and use it in GitHub Desktop.
Kiểm tra xem phần tử có tồn tại hay chưa
// Tiny jQuery Plugin
// by Chris Goodchild
$.fn.exists = function(callback) {
var args = [].slice.call(arguments, 1);
if (this.length) {
callback.call(this, args);
}
return this;
};
// Usage
$('div.test').exists(function() {
this.append('<p>I exist!</p>');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment