.frontpush(array)
Description
Places the matched set of elements at the front of an array.
Download the ZIP File with Source and Demo
Parameters:
- array: The array that will be manipulated
Due to scope issues, the JavaScript array method .unshift() sometimes fails to function properly. This is often followed by an error in FireBug stating .unshift() is not a function. Sometimes the scope issue is extremely difficult to find, and it's easier to simply use this plugin to insert jQuery objects at the front of an array.
Demos
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="frontpush.jquery.js"></script>
<script type="text/javascript">
$(function(){
var boxes = $("#box1");
$(".box").frontpush(boxes);
console.log(boxes); //Outputs [div#box2.box, div#box3.box, div#box1]
});
</script>
</head>
<body>
<div id="box1"></div>
<div class="box" id="box2"></div>
<div class="box" id="box3"></div>
</body>
</html>
Download the ZIP File with Source and Demo
August 10, 2010