I have several html tables on my page and I want to be able to sort them based on the value of one of their cell values. Here is an example of my tables
<div id="tables">
<table class="sortable">
<tr>
<td>Comic Book Name</td>
<td id="comic">Batman</td>
</tr>
<tr>
<td>Main Character</td >
<td ="character">Bruce Wayne</td>
</tr>
<tr>
<td>Hero Name</td>
<td id="hero">Batman</td>
</tr>
<tr>
<td>Published</td>
<td id="publish">05/01/1940</td>
</tr>
</table>
<table class="sortable">
<tr>
<td>Comic Book Name</td>
<td id="comic">Green Arrow</td>
</tr>
<tr>
<td>Main Character</td >
<td ="character">Oliver Queen</td>
</tr>
<tr>
<td>Hero Name</td>
<td id="hero">Green Arrow</td>
</tr>
<tr>
<td>Published</td>
<td id="publish">11/01/1941</td>
</tr>
</table>
</div>
I am providing the following drop down to allow users to filter.
<select id="OrderBy">
<option selected="selected" value="comic">Comic Name</option>
<option value="character">Character Name</option>
<option value="hero">Hero Name</option>
<option value="publish">Earliest Publish Date</option>
</select>
My hopes here are to sort the tables alphabetically by Comic book name when they choose Comic Name, alphabetically by Character Name when they select character name etc. etc.
Here is the javascript/jquery I have come up with so far. I'm sure this could be done better but I'm new to Javascript and Jquery.
$('#OrderBy').on('change', function () {
_order = $('#OrderBy').val();
switch (_order) {
case "comic":
$('#sortable').sort(function () {
});
break;
case "character":
$('#sortable').children().sort(function (a, b) {
});
break;
case "publish":
$('#sortable').sort(function () {
});
break;
case "publish":
$('#sortable').sort(function () {
if ($(b).children().find('#Hours').text() - $(a).children().find('#publish').text() <= 0) {
return $(a) - $(b);
}
return $(b) - $(a);
});
break;
}
});
Everywhere I look someone suggests Sorttables or tableSorter but I've only seen how they would work for a single table whose rows are being sorted. I know what everyone is thinking at this point, don't use tables this way. My problem is there is already a bunch of jquery and javascript supporting the tables and I'm not experienced enough in the languages to re-write all of that.
I like the idea of pushing everything onto a stack as described here but I always generated an error about how my array/stack was not defined.
First, you should not put several times the same id, but use classes instead:
<div id="tables">
<table class="sortable">
<tr>
<td>Comic Book Name</td>
<td class="comic">Green Arrow</td>
</tr>
<tr>
<td>Main Character</td >
<td class="character">Oliver Queen</td>
</tr>
<tr>
<td>Hero Name</td>
<td class="hero">Green Arrow</td>
</tr>
<tr>
<td>Published</td>
<td class="publish">11/01/1941</td>
</tr>
</table>
<table class="sortable">
<tr>
<td>Comic Book Name</td>
<td class="comic">Batman</td>
</tr>
<tr>
<td>Main Character</td >
<td class="character">Bruce Wayne</td>
</tr>
<tr>
<td>Hero Name</td>
<td class="hero">Batman</td>
</tr>
<tr>
<td>Published</td>
<td class="publish">05/01/1940</td>
</tr>
</table>
</div>
For your problem, I would use the native Array.prototype.sort method
var tables = [];
var $tables = $("table.sortable");
var container = $("#tables");
// this is the only specific case, as the date does not start by the year
// it will be used to sort by publish date
function sortByDate(a, b) {
return new Date(a.publish).getTime() - new Date(b.publish).getTime();
}
function sortTables(order) {
var sort;
if (order === "publish") {
tables = tables.sort(sortByDate);
} else {
tables = tables.sort(function(a, b) {
return a[order] < b[order] ? -1 : 1;
});
}
tables.forEach(function(data,i) {
tables[i].$el.detach()
container.append(tables[i].el);
});
}
function init() {
//populate the tables array that will be sorted
$tables.each(function(i, val) {
var $this = $(this);
tables.push({
$el: $this,
el: this,
comic: $this.find(".comic").text(),
character: $this.find(".character").text(),
hero: $this.find(".hero").text(),
publish: $this.find(".publish").text()
});
});
$("#OrderBy").on("change", function(event) {
sortTables(event.currentTarget.value);
});
//by default sort by Hero
sortTables("hero");
}
init();
Primarily, Sort can't happen when you have data in two different tables. To make it possible, you need to put id to them, not just classes because your primary issue isn't CSS. Again, if you put same id to different contents, it can't be spotted specifically. So, debugged code would be:
<div id="tables">
<table id="tbl1" class="sortable">
<tr>
<td>Comic Book Name</td>
<td class="comic">Batman</td>
</tr>
<tr>
<td>Main Character</td >
<td class="character">Bruce Wayne</td>
</tr>
<tr>
<td>Hero Name</td>
<td class="hero">Batman</td>
</tr>
<tr>
<td>Published</td>
<td class="publish">05/01/1940</td>
</tr>
</table>
<table id="tbl2" class="sortable">
<tr>
<td>Comic Book Name</td>
<td class="comic">Green Arrow</td>
</tr>
<tr>
<td>Main Character</td >
<td class="character">Oliver Queen</td>
</tr>
<tr>
<td>Hero Name</td>
<td class="hero">Green Arrow</td>
</tr>
<tr>
<td>Published</td>
<td class="publish">11/01/1941</td>
</tr>
</table>
Your drop-down menu(filter box) is properly defined. Now, in js code, there are some syntactical mistakes.
like, 'class' identifier is '.', 'id' identifier is '#', you used '#' instead of '.' some places :
switch (_order) {
case "comic":
$('#sortable').sort(function () {});
debugged code would be:
$('#OrderBy').on('change', function () {
_order = $('#OrderBy').val();
switch (_order) {
case "comic":
$('.sortable').sort(function () {});
break;
case "character":
$('.sortable').children().sort(function (a, b) {
});
break;
case "publish":
$('.sortable').sort(function () {
});
break;
case "publish":
$('.sortable').sort(function () {
if ($(b).children().find('#Hours').text() - $(a).children().find('#publish').text() <= 0) {
return $(a) - $(b);
}
return $(b) - $(a);
});
break;
}});
There's no official table sort() function jquery library. It would work for array only, but you won't have any array here.
So we make a sort function on our own. We can name it 'sortTable()'. The code for this should be:
<!-- -------------------------------------------------------------- -->
<!-- Secondary functions -->
<!-- Creates a new table to display the sorted Table -->
function createEmptyTable(){
var outerDiv = document.createElement('div');
outerDiv.setAttribute('id','ResultTable');
var innerTable = doucment.createElement('table');
innerTable.setAttribute('id','sortedTable');
var newRows = new Array();
var recordIndex = document.getElementsByClassName('comic');
innerTable.innerHTML = "<tr> <th>Comic Book Name </th> <th>Main Character</th> <th>Hero Name</th> <th>Published</th> </tr>";
for(var i=0; i<recordIndex.Length;i++){
newRows[i]= document.createElement('tr');
outerDiv.appendChild(innerTable).appendChild(newRows[i]);
}
}
<!-- ------------------------------------------------------------- -->
<!-- function to find out in which table chosen filter belongs -->
function recordSearch(keyWord){
var sortableTables = document.getElementsByClassName('sortable');
for( var i=0; i<sortableTables.length;i++){
if($(sortableTables[i]).find(keyword)){
return sortableTable[i];
}
}
<!-- ------------------------------------------------------------- -->
<!-- Primary function to sort the Table -->
function sortTable(filtered_option){
<!-- first we delete any existing sorted table -->
if(document.getElementById('ResultTable')){
var existingSortedTable = document.getElementbyId('ResultTable');
existingSortedTable.removeChild(document.getElementById('sortedTable');
}
<!-- now we create new table & put the result -->
createEmptyTable();
var comicNames = document.getElementsByClassName('comic');
var characterNames = document.getElementsByClassName('character');
var heroNames = document.getElementsByClassName('hero');
var publishDates = document.getElementsByClassName('publish');
switch (filtered_option) {
case 'comic' :
var sortedComicNames = comicNames.sort();
for(var i=0;i<sortedComicNames.length;i++){
var foundRecord = recordSearch(sortedComicNames[i]);
var allFields = foundRecord.getElementByTagName('tr').getElementsByClassName('td');
var emptyRows = document.getElementById('sortedTable').getElementsByTagName('tr');
for(var j=0;j<allFields.length;j++){
emptyRows[i+1].innerHTML = "<td>" + allFields[j].value + "</td>" ;
}}
break;
case 'character' :
var sortedCharacterNames= characterNames.sort();
for(var i=0;i<characterNames.length;i++){
var foundRecord = recordSearch(sortedCharacterNames[i]);
var allFields = foundRecord.getElementByTagName('tr').getElementsByClassName('td');
var emptyRows = document.getElementById('sortedTable').getElementsByTagName('tr');
for(var j=0;j<allFields.length;j++){
emptyRows[i+1].innerHTML = "<td>" + allFields[j].value + "</td>" ;
}}
break;
case 'hero' :
var sortedHeroNames= heroNames.sort();
for(var i=0;i<heroNames.length;i++){
var foundRecord = recordSearch(heroNames[i]);
var allFields = foundRecord.getElementByTagName('tr').getElementsByClassName('td');
var emptyRows = document.getElementById('sortedTable').getElementsByTagName('tr');
for(var j=0;j<allFields.length;j++){
emptyRows[i+1].innerHTML = "<td>" + allFields[j].value + "</td>" ;
}}
break;
case 'publish' :
var sortedPublishedDates= publishedDates.sort();
for(var i=0;i<publishedDates.length;i++){
var foundRecord = recordSearch(publishedDates[i]);
var allFields = foundRecord.getElementByTagName('tr').getElementsByClassName('td');
var emptyRows = document.getElementById('sortedTable').getElementsByTagName('tr');
for(var j=0;j<allFields.length;j++){
emptyRows[i+1].innerHTML = "<td>" + allFields[j].value + "</td>" ;
}}
break;
}
}
<!-- -------------------------------------------------------------------- -->
Put them together and Try. Let me know if it works.
Related
I am trying to sort the table using javascript to order by total points at the end. The table is a dynamic one so W1, W2, W3 columns adds up to total. Is there way to order rows them by total in javascript. Each row is dynamically created as well.
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table class="fl-table">
<thead>
<tr>
<th>Player</th>
<th>Player Name</th>
<!-- <th>W1</th>
<th>W2</th> -->
<th>W1</th>
<th>W2</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<tr>
<td class="agl-profile-img-new"><img src="https://via.placeholder.com/70
C/O https://placeholder.com/"></td>
<td>Heather Rankin</td>
<td>4</td>
<td>21</td>
<td>25</td>
</tr>
<tr>
<td class="agl-profile-img-new"><img src="https://via.placeholder.com/70
C/O https://placeholder.com/"></td>
<td>Stephen Puopolo</td>
<td>3</td>
<td>1</td>
<td>4</td>
</tr>
<tr>
<td class="agl-profile-img-new"><img src="https://via.placeholder.com/70
C/O https://placeholder.com/"></td>
<td>Latheesh V M V</td>
<td>2</td>
<td>26</td>
<td>28</td>
</tr>
</tbody>
<tbody>
</tbody>
</table>
Is there is any way? Please help
can you gather the cells into object and sort them like this. https://jsfiddle.net/e4oscnz8/4/
const sortTotal = () => {
const tbl = [...document.getElementsByClassName("fl-table")][0];
const tbody = [...tbl.tBodies][0];
const oObjects = [];
[...tbody.rows].forEach(row => {
const cells = [...row.cells];
const obj = [...row.cells].map(cell => {
return cell.innerHTML;
});
oObjects.push(obj);
});
oObjects.sort((a, b) => a[a.length -2] > b[b.length -2] ? 1 : -1);
[...tbody.rows].forEach((row, i) => {
[...row.cells].forEach((cell, j) => {
cell.innerHTML = oObjects[i][j];
});
});
}
push tr rows into array or object and sort by your custom sort function: https://jsfiddle.net/2dq7m8k9/
you are using jquery so life is good :)
function SortByTotal(tr1, tr2){//descending sorting
var total1 = parseInt(tr1.find('td:last-child').text());
var total2 = parseInt(tr2.find('td:last-child').text());
return ((total1 > total2) ? -1 : ((total1 < total2) ? 1 : 0));
}
var trs=new Array();
$('#mytable tbody').first().children('tr').each(function(){
trs.push($(this).clone());
});
trs.sort(SortByTotal);
$('#mytable tbody').first().empty();
var i=0;
for (i = 0; i < trs.length; i++) {
$('#mytable tbody').first().append(trs[i]);
}
I have the following table:
<table>
<tr>
<th>Category</th>
<th>Value</th>
</tr>
<tr>
<td class="cat1">cat1</td>
<td class="value">123</td>
</tr>
<tr>
<td class="cat2">cat2</td>
<td class="value">356</td>
</tr>
<tr>
<td class="cat1">cat1</td>
<td class="value">486</td>
</tr>
</table>
I need a way to add/sum all values grouped by category, ie: add/sum all values in cat1, then add/sum all values in cat2. For each group I will do something with the total.
So I was hoping for something like:
for each unique category:
sum values in category
do something with this category total
For cat1 the total would be 123 + 486. Cat2 would just be 356. And so on if there were more categories.
I would prefer a purely javascript solution, but JQuery will do if that's not possible.
If I understand you correctly, you do a repeat of each td:first-child (The category cell).
Create a total object. You can check if the category is exist in it for each cell. If so, add current value to the stored value. If not, insert new property to it.
Like this:
var total = {};
[].forEach.call(document.querySelectorAll('td:first-child'), function(td) {
var cat = td.getAttribute('class'),
val = parseInt(td.nextElementSibling.innerHTML);
if (total[cat]) {
total[cat] += val;
}
else {
total[cat] = val;
}
});
console.log(total);
<table>
<tr>
<th>Category</th>
<th>Value</th>
</tr>
<tr>
<td class="cat1">cat1</td>
<td class="value">123</td>
</tr>
<tr>
<td class="cat2">cat2</td>
<td class="value">356</td>
</tr>
<tr>
<td class="cat1">cat1</td>
<td class="value">486</td>
</tr>
</table>
Here's a simple approach using only javascript
//grab data
var allTR = document.getElementsByTagName('TR');
var result = {};
//cycle table rows
for(var i=0;i<allTR.length;i+2){
//read class and value object data
var class = allTR[i].getAttribute('class');
var value = allTR[i+1].innerText;
//check if exists and add, or just add
if(result[class])
result[class] += parseInt(value);
else
result[class] = parseInt(value);
}
You have to use getElementsByTagName("td"); to get all the <td> collection and then you need to loop through them to fetch their innerText property which later can be summed up to get the summation.
Here is the working Fiddle : https://jsfiddle.net/ftordw4L/1/
HTML
<table id="tbl1">
<tr>
<th>Category</th>
<th>Value</th>
</tr>
<tr>
<td class="cat1">cat1</td>
<td class="value">123</td>
</tr>
<tr>
<td class="cat2">cat2</td>
<td class="value">356</td>
</tr>
<tr>
<td class="cat1">cat1</td>
<td class="value">486</td>
</tr>
<tr>
<td class="total"><b>Total</b></td>
<td class="totalValue"></td>
</tr>
</table>
Javascript
var tds=document.getElementsByTagName("td");
var total=0;
for (var i = 0; i<tds.length; i++) {
if (tds[i].className == "value") {
if(total==0) {
total = parseInt(tds[i].innerText);
} else {
total = total + parseInt(tds[i].innerText);
}
}
}
document.getElementsByClassName('totalValue')[0].innerHTML = total;
Hope this helps!.
here is a solution with jQuery :) if you are interested. it's pretty straightforward
var sumCat1 = 0;
var sumCat2 = 0;
$(".cat1 + .value").each(function(){
sumCat1 += parseInt($(this).text());
})
$(".cat2 + .value").each(function(){
sumCat2 += parseInt($(this).text());
})
console.log(sumCat1)
console.log(sumCat2)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<th>Category</th>
<th>Value</th>
</tr>
<tr>
<td class="cat1">cat1</td>
<td class="value">123</td>
</tr>
<tr>
<td class="cat2">cat2</td>
<td class="value">356</td>
</tr>
<tr>
<td class="cat1">cat1</td>
<td class="value">486</td>
</tr>
</table>
A simple approach in JQuery...
var obj = {};
$('tr').each(function() {
$this = $(this)
if ($this.length) {
var cat = $(this).find("td").first().html();
var val = $(this).find("td").last().html();
if (cat) {
if (!obj[cat]) {
obj[cat] = parseInt(val);
} else {
obj[cat] += parseInt(val);
}
}
}
})
console.log(obj)
I have this code:
<table>
<tbody>
<tr><td>Table 1</td></tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td align="left">Number</td>
<td><b>33</b></td>
</tr>
<tr>
<td width="150" align="left">Field</td>
<td>XXXX</td>
</tr>
<tr>
<td align="left">Select: </td>
<td colspan="4">
<select name="status" size="1">
<option selected="selected" value="2">one</option>
<option value="1">two</option>
</select>
</td>
</tr>
</tbody>
</table>
and i want to remove this line by searching "Field" with pure Javascript:
<tr>
<td width="150" align="left">Field</td>
<td>XXXX</td>
</tr>
when there is a 33, 66 or 99 in this line from my 2nd table:
<tr>
<td align="left">Number</td>
<td>33</td>
</tr>
The problem is that i don't have any id's or classes for identification! i want to use the code with Greasemonkey.
Here you can see a JSFIDDLE of my table.
And here you can see on JSFIDDLE how it should look.
Best regards bernte
Here you go:
var disallowedValues = ['33', '66', '99'];
var cols = document.getElementsByTagName('td');
var colslen = cols.length;
var i = -1;
var disallowedTable;
while(++i < colslen){
// look for the td where the disallowed values are
if(disallowedValues.indexOf(cols[i].innerHTML) >= 0)
{
// get the table where the disallowed values is
disallowedTable = cols[i].parentNode.parentNode.parentNode;
// break the cicle to stop looking for other rows
//break;
}
}
// look for the 'Field' value only on the table that has the disallowed value
var cols = disallowedTable.getElementsByTagName('td');
cols = disallowedTable.getElementsByTagName('td');
colslen = cols.length;
i = -1;
while(++i < colslen){
// look for the td where the 'Field' value is
if(cols[i].innerHTML == 'Field')
{
// get the tr for such td
var deletionTR = cols[i].parentNode;
//delete that tr
deletionTR.parentNode.removeChild(deletionTR);
// break the cicle to stop looking for other rows
break;
}
}
You can always do a simpler version if jquery is an option.
Trying to store all the information that getting from JSONP in the table.
Have done the test with 'alert' to make sure that there are more info that only one line and can see that there are more info that one.
But when run it, in the table I can see title row and first row.
Can somebody correct my error?
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js">
</script>
<script>
jQuery(document).ready(function($) {
$.ajax({
url : "http://api.example.com/v1/deal/hotel?apikey=xxx&format=JSONP",
dataType : "jsonp",
success : function(parsed_json) {
$.each(parsed_json.Result, function( index, value ) {
alert( index + ": " + value.StarRating + " , "+ value.Url);
});
var from = parsed_json['Result'][0]['StartDate'];
document.getElementById("from").innerHTML = from;
var from = parsed_json['Result'][0]['StartDate'];
document.getElementById("from").innerHTML = from;
var to = parsed_json['Result'][0]['EndDate'];
document.getElementById("to").innerHTML = to;
var nights = parsed_json['Result'][0]['NightDuration'];
document.getElementById("nights").innerHTML = nights;
var currency = parsed_json['Result'][0]['CurrencyCode'];
document.getElementById("currency").innerHTML = currency;
var price = parsed_json['Result'][0]['Price'];
document.getElementById("price").innerHTML = price;
var link = parsed_json['Result'][0]['Url'];
document.getElementById("link").innerHTML = link;
//how to represent enlaces
var city = parsed_json['Result'][0]['City'];
document.getElementById("city").innerHTML = city;
var country = parsed_json['Result'][0]['CountryCode'];
document.getElementById("country").innerHTML = country;
var stars = parsed_json['Result'][0]['StarRating'];
document.getElementById("stars").innerHTML = stars;
}
});
});
</script>
</head>
<body>
<table id="t">
<tr>
<th>Start date</th>
<th>End date</th>
<th>Nights</th>
<th>Currency</th>
<th>Price</th>
<th>Link</th>
<th>City</th>
<th>Country Code</th>
<th>Star Rating</th>
</tr>
<tr>
<td id="from"></td>
<td id="to"></td>
<td id="nights"></td>
<td id="currency"></td>
<td id="price"></td>
<td id="link"></td>
<td id="city"></td>
<td id="country"></td>
<td id="stars"></td>
</tr>
</table>
</body>
</html>
The result of the Ajax callback is:
callback({"Errors":[],"Result":[{"FoundDate":"2013-12-04T16:11:36-08:00","CurrencyCode":"USD","NightDuration":"2.0","EndDate":"12/08/2013","Headline":"Cairo 5 Star Hotel, $36/night","IsWeekendStay":"true","Price":"36.0","StartDate":"12/06/2013","Url":"http‍://www.example.com/hotel/...&startDate=12/06/2013&endDate=12/08/2013&bid=0&sid=0","City":"Cairo","CountryCode":"EG","NeighborhoodLatitude":"30.0152","NeighborhoodLongitude":"31.1756","Neighborhood":"Cairo West - Giza","StarRating":"5.0","StateCode":"EG"},{"FoundDate":"2013-12-04T14:51:44-08:00",
If you have more than one line in result, then you have to -
Loop through it in the callback. You are not looping through it now. You are looping only for alert.
Dynamically create a new row in table for each line. You can clone the exiting tr for this using jquery clone method. But replace the id with 'class`.
Add data to that row pertaining to the line by modifying innerHtml of each td in the newly created row.
Finally, Append the row to the table
HTML -
<table id="t">
<tr>
<th>Start date</th>
<th>End date</th>
<th>Nights</th>
<th>Currency</th>
<th>Price</th>
<th>Link</th>
<th>City</th>
<th>Country Code</th>
<th>Star Rating</th>
</tr>
<tr class="first">
<td class="from"></td>
<td class="to"></td>
<td class="nights"></td>
<td class="currency"></td>
<td class="price"></td>
<td class="link"></td>
<td class="city"></td>
<td class="country"></td>
<td class="stars"></td>
</tr>
</table>
Javascript -
success : function(parsed_json) {
$.each(parsed_json.Result, function( index, record ) {
$row = $('.first').clone();
var from = record['StartDate'];
$row.find('.from').html(from);
//Similarly repeat the above two lines for other columns
//...
$('#t').append($row);
});
}
I want give every element in a table a generated id. See this html table below:
<table>
<tbody>
<tr>
<td>A1</td>
<td>A2</td>
<td>
A3
</td>
</tr>
<tr>
<td>B1</td>
<td>B2</td>
<td>
B3
</td>
</tr>
<tr>
<td>C1</td>
<td>C2</td>
<td>C3</td>
</tr>
</tbody>
</table>
I want to give each element an id using breadth-first traversal. So, the result becomes like this:
<table>
<tbody id="0">
<tr id="1">
<td id="4">A1</td>
<td id="5">A2</td>
<td id="6">
A3
</td>
</tr>
<tr id="2">
<td id="7">B1</td>
<td id="8">B2</td>
<td id="9">
B3
</td>
</tr>
<tr id="3">
<td id="10">C1</td>
<td id="11">C2</td>
<td id="12">C3</td>
</tr>
</tbody>
</table>
I have tried the each() function in jQuery to generate the id for every element in that table, but the traversal algorithm used in each() function is pre order traversal.
Can anyone suggest me the Javascript code to do this?
var n = 0
var level = $("table");
while (level.children().length) {
level = level.children().each(function(_, el) {
el.id = n++;
})
}
DEMO: http://jsfiddle.net/J5QMK/
If you want to avoid the redundant .children() call, you can do this:
while ((level = level.children()).length) {
level.each(function (_, el) {
el.id = n++;
})
}
DEMO: http://jsfiddle.net/J5QMK/1/
A common way to do a breadth-first search is to use a queue as follows:
jQuery(document).ready(function () {
var ctr = 0;
var queue = [];
queue.push(jQuery("table").children()); // enqueue
while (queue.length > 0) {
var children = queue.shift(); // dequeue
children.each(function (ix, elem) {
queue.push( // enqueue
jQuery(elem).attr("id", ctr++).children();
);
console.log(elem.tagName + ": " + elem.id);
});
}
});