Trigger trigger click event does not work as expected

0

I'm using the Wordpress MetaSlider plugin for slides, and it's possible to add links to the images.

I created a button and need to simulate click , just as I was clicking on the currently active image in the slider. I'm using trigger to do the simulation, but I can not make trigger work.

<div class="img-slider">
        <?php
            echo do_shortcode("[metaslider id=135]");
        ?>
        <div class="div-button-box-slider">
            <button class="button saiba-mais"> SAIBA MAIS </button>

        </div>
    </div>

Image of the code generated by the plugin: Script:

<script>jQuery('.saiba-mais').click(function(e){e.preventDefault();console.log("You clicked!" );
    jQuery(".flex-viewport .slides .flex-active-slide a").trigger("click");
});

    
asked by anonymous 18.06.2015 / 02:04

2 answers

0

I was able to resolve the problem based on this link link

Result: <script> jQuery('.saiba-mais').on('click', function (e) { e.preventDefault(); var target = jQuery(".flex-active-slide a"); console.log("You clicked in " + target.attr('href')); console.log(target[0]); target[0].click(); }); </script>

    
18.06.2015 / 14:54
0

It is likely that the selector is wrong, to make the test use console.log (I noticed that you are already familiar with the advanced features of the browser and javascript so I will not go into detail), for example:

jQuery('.saiba-mais').click(function (e) {
    e.preventDefault();
    var target = jQuery(".flex-viewport .slides .flex-active-slide a");
    console.log("You clicked!", target.length);
    target.trigger("click");
});
  • No console.log should appear something like:

      

    You clicked !, 2

  • If it appears:

      

    You clicked !, 0

    It means the selector is incorrect. 0 indicates that no elements were found.

18.06.2015 / 04:25