最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - JQuery Error in theme for .live is not a function

programmeradmin0浏览0评论
Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 4 years ago.

Improve this question

I am trying to figure out how to fix an error the Chrome console revealed for the theme I use that has been there for quite some time. I don't know javascript so not sure how to fix it, after some research and reading my only guess is .live should be .on as per the error it is using JQuery 1.12.4 and I read .live was removed starting in version 1.9. I posted on the theme makers forum, but I figure I would get help quicker here. Here is the code block the error points to, it points to ".live('click', function(event){" but includes the whole section, I did notice a missing } at the end as well, I left the block below exactly how it is in the functions.js file.

$('.hm_icon_search > a, .top_add_card').live('click', function(event){

var parent = $(this).parent();

var $this_btn = $(this);

var $target_block = $this_btn.siblings('div');

event.preventDefault();

event.stopPropagation();

if(parent.hasClass('active') && $target_block.hasClass('hm_active_prep')){

$target_block.fadeOut(function(){

    parent.removeClass('active');
    }
 }

});
Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 4 years ago.

Improve this question

I am trying to figure out how to fix an error the Chrome console revealed for the theme I use that has been there for quite some time. I don't know javascript so not sure how to fix it, after some research and reading my only guess is .live should be .on as per the error it is using JQuery 1.12.4 and I read .live was removed starting in version 1.9. I posted on the theme makers forum, but I figure I would get help quicker here. Here is the code block the error points to, it points to ".live('click', function(event){" but includes the whole section, I did notice a missing } at the end as well, I left the block below exactly how it is in the functions.js file.

$('.hm_icon_search > a, .top_add_card').live('click', function(event){

var parent = $(this).parent();

var $this_btn = $(this);

var $target_block = $this_btn.siblings('div');

event.preventDefault();

event.stopPropagation();

if(parent.hasClass('active') && $target_block.hasClass('hm_active_prep')){

$target_block.fadeOut(function(){

    parent.removeClass('active');
    }
 }

});
Share Improve this question edited Aug 16, 2020 at 6:48 JustWondering asked Aug 16, 2020 at 6:31 JustWonderingJustWondering 33 bronze badges 1
  • Hi, welcome to WordPress Development. As a rule, many in the community consider questions about third-party themes and plugins to be off-topic so you might notice some down-votes and answers may be slow if they come at all. You are likely to be pointed to the theme author for support. You can find out what questions are a good fit here. – Matthew Brown aka Lord Matt Commented Aug 16, 2020 at 15:23
Add a comment  | 

1 Answer 1

Reset to default 1

If you asking what is the replacement for .live() it's .on()`, for enabling event handling for dynamically added elements and that's how you would use it.

$(document).on("click","#test-element",function() {});

so for your code.

$('body').on('click', '.top_add_card', function(event){

    var parent = $(this).parent();
    var $this_btn = $(this);
    var $target_block = $this_btn.siblings('div');
    
    event.preventDefault();
    event.stopPropagation();
    
    if(parent.hasClass('active') && $target_block.hasClass('hm_active_prep')){
        $target_block.fadeOut(function(){
            parent.removeClass('active');
        }
    }
});

This would work for dynamically adding elements too. because thats the main purpose of using .on(). read more about it here. https://api.jquery/on/

发布评论

评论列表(0)

  1. 暂无评论