Sanjeev K Sanjeev K - 22 days ago 16
Javascript Question

Add class and then fire an event JQuery

I am trying to add class and then fire an event, but unfortunately its not working and I think I am trying in wrong way, can somebody please suggest? Following are my codes

First I want to add class

$(".hospital_listing_front").addClass('flexslider-hospital');


Once the class is added then fire the following function (This is related to flexslider and will add flexslider functionality)

$(".flexslider-hospital").flexslider({
animation: "slide",
animationLoop: false,
itemWidth: 210,
itemMargin: 48,
pausePlay: false
});


Add class is working but flexslider is not working

Please suggest how to handle this.

thanks in advance

Answer

I thought it may be have provide some time to add class. Like may be use setTimeout will solve your problem just try and let me know if you face again the same issue.

$(".hospital_listing_front").addClass('flexslider-hospital');

setTimeout(function() {
    $(".flexslider-hospital").flexslider({
    animation: "slide",
    animationLoop: false,
    itemWidth: 210,
    itemMargin: 48,
    pausePlay: false
    });
}, 1000);
Comments