Created
April 22, 2016 10:03
-
-
Save anonymous/66142e535b1a1906e59c549e1473fd9c to your computer and use it in GitHub Desktop.
PushStack demo jQuery pushStack() demo // source http://jsbin.com/wicama
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="description" content="jQuery pushStack() demo"> | |
<script src="https://code.jquery.com/jquery-2.1.4.js"></script> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>PushStack demo</title> | |
</head> | |
<body> | |
<h1>PushStack Demo</h1> | |
<input type="button" value="Click me" id="clickme" /> | |
<div id="out1">1</div> | |
<div id="out2">2</div> | |
<div id="out3">3</div> | |
<div id="out4">4</div> | |
<div id="out5">5</div> | |
<div id="out6">6</div> | |
<div id="out7">7</div> | |
<script id="jsbin-javascript"> | |
$(function() { | |
$.fn.everyThird = function() { | |
var arr = []; | |
$.each(this, function(idx, item) { | |
if(idx % 3 === 0) { | |
arr.push(item); | |
} | |
}); | |
return this.pushStack(arr, 'everyThird', ''); | |
}; | |
$('#clickme').click(function() { | |
$('div').everyThird().css('color', 'red').end().css('font-weight', 'bold'); | |
}); | |
}); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">$(function() { | |
$.fn.everyThird = function() { | |
var arr = []; | |
$.each(this, function(idx, item) { | |
if(idx % 3 === 0) { | |
arr.push(item); | |
} | |
}); | |
return this.pushStack(arr, 'everyThird', ''); | |
}; | |
$('#clickme').click(function() { | |
$('div').everyThird().css('color', 'red').end().css('font-weight', 'bold'); | |
}); | |
});</script></body> | |
</html> |
This file contains 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
$(function() { | |
$.fn.everyThird = function() { | |
var arr = []; | |
$.each(this, function(idx, item) { | |
if(idx % 3 === 0) { | |
arr.push(item); | |
} | |
}); | |
return this.pushStack(arr, 'everyThird', ''); | |
}; | |
$('#clickme').click(function() { | |
$('div').everyThird().css('color', 'red').end().css('font-weight', 'bold'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment