some tex...">

Jquery click is limited but does not fire on click

I got this piece of code

<div id="boxInformacion" class="alert-box success"><span>some text</span></div>

and in some .js file

var c = $('#boxInformacion');

c.on('click', function(){
    // some code
});

setTimeout(function(){
    c.click();
}, 9999);

(this is a bit more complicated function inside the click event, so it is simplified)

This code runs after ajax call on success. The problem is that I click on the div, but nothing happens. I put a timeout just to verify the binding is correct, and yes, after 9 seconds, the click starts javascript and it works. Div #boxInformacionis the only one in all HTMLwith this Id.

As soon as the click in the timeout works fine, it seems like this is a mistake in manually clicking. I checked from the console and I click on the right place. What can i skip?

I click on the green panel.

I also tried using c.click(function(){ /* code */})instead.on('click', function(){ /* code*/ })

enter image description here

I use jQuery 1.10.2

Feed here

+4
2

. CSS:

z-index:-100;

- z- . , .

​​

+4

, .

 <script>
 $(document).ready(function(){
     var c = $('#boxInformacion');

     c.on('click', function(){
       alert(1);
     });

  })
 </script>

body

<div id="boxInformacion" class="alert-box success"><span>CLICK</span></div>
-3

Source: https://habr.com/ru/post/1538322/


All Articles