rob.m rob.m - 1 month ago 8
jQuery Question

Uncaught TypeError: $thirdColumnCells.each is not a function

I am running this but I have the console keeps giving me the error in the question title. basically I am reading the

href
value from a link and I am pushing it into a
<ul>


HTML

<div id="link"><ul></ul></div>


JQUERY

var $thirdColumnCells = $hiddenContentB.find('table.wikitable tr').find('td:nth-child(3) a').attr("href");

$thirdColumnCells.each(function(idx, cell) {
var valB = $(cell).text().match(/\d+/)[0];
valuesB.push($(cell).html());
$('#link').append('<li>'+ valB + '</li>');
});

Answer

jQuery's .attr() returns a string.

jQuery's .each() iterates over objects and arrays, usually array-like objects holding elements

What you're doing is

var $thirdColumnCells = $(element).attr("href");

$thirdColumnCells.each(... // <- that's a string !!!
Comments