How to get the value of a td with id in jquery


How to get the value of a td with id in jquery



I want to get the value of TD with its id. When I am trying to get the value of TD by the following code getting a null value.


function deletediv(ele){
var r = $("#row_ #price_"+ele).text();
alert(r);
}



here I am trying to fetch the value in TD using forloop.


for(var i=0 ; i< data[1].product.length ; i++ ){
var product_name = data[1].product[i].product_name;
var product_code = data[1].product[i].product_code;
var product_price = data[1].product[i].price;
var product_qty = data[1].product[i].qty;

var row_count = i;

var cell = $('<tr id="row_'+row_count+'"><td>'+product_code+'</td><td>'+product_name+'</td><td id="price_'+row_count+'">'+product_price+'</td><td><input type="text" class="form-control" name="qty_'+row_count+'" value="'+product_qty+'" style="width: 50%;" /></td><td> <input id="box_'+row_count+'" type="checkbox" name="cond_'+row_count+'" /><label for="box_'+row_count+'"><?php echo $lang_good; ?></label> </td><td><a onclick="deletediv('+row_count+')" class="btn btn-danger" style="cursor:pointer"><i class="fa fa-trash-o"></i></a></td></tr><input type="hidden" class="form-control" name="pcode_'+row_count+'" value="'+product_code+'" />');

$('#addItemWrp').append(cell);
}




1 Answer
1



Your selector is wrong because there is nothing with id row_. Instead of looking for the row then the cell in the selector just look for the row since ids should be unique.


row_


var r = $("#price_"+ele).text();






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Export result set on Dbeaver to CSV

Opening a url is failing in Swift