Dynamitaclly added HTML in JQUERY class events not working

So I did this

$('div#faq_search_result').replaceWith(decodeHtml(data.html_result));

It seems fine but the on click events is not working

this class won't work

dt class= "c-faqList__dt"

Code for the JS

var dfd = new $.Deferred();
var self = this;
self.$elm = elm;

self.$elm.on('click','.c-faqList__dt',function(event){
    $(this).siblings('.c-faqList__dd').slideToggle(100)
});

dfd.resolve();
return dfd.promise();

Answers 1

  • try something like this:

    $('div#faq_search_result').parent().on('click','.c-faqList__dt',function(event){
        $(this).siblings('.c-faqList__dd').slideToggle(100)
    });
    

    assumption: .c-faqList__dt is inside div#faq_search_result


Related Articles