简体   繁体   中英

This as parameter in other function in jquery

I'm trying to send $(this) as parameter to other function after user clicks on a row and than after click button append some text to clicked row.

My problem is that I want to append only to last clicked row, not to all row's and append text only once

When I click 10 times on row and than click button, text append 10 times.

This is my code:

$('#Page').on('click', '.row', function(e) {
  var ths = this;
  addText(ths);
});

function addText(ths) {
  $('.addtext').click(function() {
    $(ths).append('teeeeeeeeeeeeeeeeeeeeeest');
    $('#tools').hide();
    ths = null;
  });
}

Detect clicked row and append it like that:

$('.row').on('click', function() {
    $(this).append('Test');
});

Working fiddle: https://jsfiddle.net/cr29y1tc/35/

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