HTML点击this,HTML Onclick with $(this)

博客内容讲述了作者在使用jQuery的click事件与HTML元素的onclick事件时遇到的冲突问题。作者需要在保留jQuery的$(this)功能的同时,为HTML元素添加onclick事件。问题的核心在于如何在不失去$(this)上下文的情况下,正确地在元素上绑定onclick事件。
摘要由CSDN通过智能技术生成

I have a conflict with calling the general jQuery click function and so I need to call an onclick event on the HTML element itself while still being able to use $(this)

$('.item-main-section, .item-status').click( function () {

var slideHeight = $(this).parent().children('.item-slide-section').height();

if ($(this).parent().height() > 50) {

$(this).parent().animate({height: '50px'}, 300);

$(this).parent().children('item-slide-section').animate({bottom: '0px'}, 300);

} else {

$(this).parent().animate({height: slideHeight + 50 + 'px'}, 300);

$(this).parent().children('item-slide-section').animate({bottom: slideHeight - 5 + 'px'}, 300);

$(this).parent().siblings('.item-wrapper').animate({height: '50px'}, 300);

$(this).parent().siblings('.item-wrapper').children('item-slide-section').animate({bottom: '0px'}, 300);

}

});

Instead of the jquery click i need οnclick="thisFunction()" on the elements but if I get rid of the first line I lose the ability to use $(this).

It's hard to explain but I hope it makes sense to someone.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值