Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save luislobo14rap/343807ea1021b016c2332dc7cb601318 to your computer and use it in GitHub Desktop.
Save luislobo14rap/343807ea1021b016c2332dc7cb601318 to your computer and use it in GitHub Desktop.
jQuery.fn.extend({indexOf:function(a){let b=$(this);if($(this).constructor==$().constructor){if('undefined'==typeof a)return $(this).index();if(!$(this).is(a))return console.error('This element is not equal to the selector.'),stopError;let c=-1;return $(this).parent().children().each(function(){if($(this).is(a)&&c++,$(this).is(b))return!1}),c}return console.error('The "indexOf" function only accepts jquery elements.'),stopError}});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment