简体   繁体   中英

Get the clicked table row element value

I know this already asked here. I referred this Link 1 , Link 2 but working the same in jquery mobile not able to get the value. I want to get column A value how to get this one.

Here is the Fiddle what i tried

Code is like:

onclick="deleteRow(this)"

function deleteRow(r) {
$(r).parent().parent().hide();

var Something = $(r).closest('tr').find('td:eq(1)').text();
alert(Something);
// this one gave the input element as child 
alert($(r).parent().parent().children().children().html);
alert($(r).parent().parent().children().children().text());

}

check this also Fiddle 1

The text you're looking for is actually the value of the input within the first td , so you need to get the val() of that element, not the text() of the td . Also note that eq() takes the index which is zero-based, so you need to use 0 to get the first td of the row. Try this:

function deleteRow(r) {
    var $row = $(r).closest('tr').hide();
    var Something = $row.find('td:eq(0) input').val();
    alert(Something);
}

Updated fiddle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM