简体   繁体   中英

jQuery closest('tr') not working in iOS

I have the following code

fnDrawCallback: function() {
    $("#rqTable tbody tr td .fa-edit").closest('td').on('click', function() {
        // log for testing
        console.log(this);
        console.log(this.closest('tr'));
        console.log(this.closest('tr').id);
    });
}

It works as expected in IE, Chrome, Firefox, Andriod but not in Safari or on an iPhone.

this is a screen shot of the console in firefox 在此输入图像描述

thisis a screen shot of the console in safari 在此输入图像描述

Is there something I should be doing different to account for the iOS difference?

As closest() is a jQuery function you need to use it with jQuery object. Similarly use .prop() to get it any property.

this refers to native DOM element, which doesn't have the above method. use the with jQuery object.

$(this).closest('tr').prop('id');
// $(this).closest('tr').prop('id'); //OR you can also use .attr()

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