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:
<div id="main_list_wrapper">
<div class="item">
<div class="t7 edit"></div>
<div class="t8 cancel"></div>
</div>
<div class="item">
<div class="t7 edit"></div>
<div class="t8 cancel"></div>
</div>
<div class="item">
<div class="t7 edit"></div>
<div class="t8 cancel"></div>
</div>
<div class="item">
<div class="t7 edit"></div>
<div class="t8 cancel"></div>
</div>
<div class="item">
<div class="t7 edit"></div>
<div class="t8 cancel"></div>
</div>
</div>
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;
}
});
});