Created
April 20, 2018 20:56
-
-
Save luislobo14rap/bc3fdf9843b8a0c9d14fa59d729db96c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery.fn.extend({ | |
indexOf: function(selector) { | |
let thisElement = $(this); | |
if ($(this).constructor == $().constructor) { | |
if (typeof selector == 'undefined') { | |
return $(this).index(); | |
}; | |
if (!$(this).is(selector)) { | |
console.error('This element is not equal to the selector.'); | |
return stopError; | |
}; | |
let index = -1; | |
$(this).parent().children().each(function() { | |
if ($(this).is(selector)) { | |
index++; | |
}; | |
if ($(this).is(thisElement)) { | |
return false; | |
}; | |
}); | |
return index; | |
} else { | |
console.error('The "indexOf" function only accepts jquery elements.'); | |
return stopError; | |
}; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment