Thursday, 14 September 2017

javascript - jquery touchwipe how to get $(this)

I am using the jquery touchwipe plugin on my scroll list, and i can't get
attribute from $(this).I want to use $(this) to get its children elment class="t7 edit" and add class 'show' to it.Does anyone know how to fix it?



html:



                



























script code:



var $main_list_wrapper = $("#main_list_wrapper").find('.item');

$main_list_wrapper.touchwipe({
preventDefaultEvents: false,
wipeLeft: function() {

$(this).find('.t8.cancel').removeClass('show');
$(this).find('.t7.edit').removeClass('show');
var thisclass = $(this).attr('class');
alert(thisclass);
return false;
},
wipeRight: function() {
$sb(this).find('.t8.cancel').addClass('show');
$sb(this).find('.t7.edit').addClass('show');
return false;

}
});


Like alert(thisclass). It shows "undefine".






Thank you all.my friend write this to me, and it work!




$main_list_wrapper.each(function () {
var $this = $sb(this);

$this.touchwipe({
preventDefaultEvents: false,
wipeLeft: function() {
var $pcs = $this;
$pcs.find('.t8').removeClass('show');
$pcs.find('.t7').removeClass('show');
return false;

},
wipeRight: function() {
var $pcs = $this;
$pcs.find('.t8').addClass('show');
$pcs.find('.t7').addClass('show');
return false;
}
});
});

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...