Why can’t I pass the num variable to this function like so:
function getColumnData(num) {
var colVals = $('#newtable td:nth-child(num)').map(function(){
return $(this).text();
}).get();
alert(colVals);
}
Is there an easy way around this?
Thanks.
You need to concatenate the value of
numwith the selector string:Currently you just have a string literal “#newtable td:nth-child(num)”, instead of something that makes sense to the selector engine, such as “#newtable td:nth-child(2)”.