Skip to content

Instantly share code, notes, and snippets.

@AliMD
Last active December 20, 2015 05:28
Show Gist options
  • Save AliMD/6078176 to your computer and use it in GitHub Desktop.
Save AliMD/6078176 to your computer and use it in GitHub Desktop.
jQuery Plugin for Select Odd and Even Elements after selected
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<div>1</div>
<div>1</div>
<div>1</div>
<div>1</div>
<div>1</div>
<div>1</div>
<div>1</div>
<div>1</div>
<div>1</div>
<div>1</div>
</body>
</html>
(function($){
$.fn.odd = function(){
var i,arr2=[],arr = jQuery.makeArray(this);
for(i=1;i<arr.length;i+=2){
arr2.push(arr[i]);
}
return $(arr2);
}
$.fn.even = function(){
var i,arr2=[],arr = jQuery.makeArray(this);
for(i=0;i<arr.length;i+=2){
arr2.push(arr[i]);
}
return $(arr2);
}
})(jQuery);
$div = $('div');
$div.odd().html('o');
$div.even().html('e');
@AliMD
Copy link
Author

AliMD commented Jul 25, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment