JQuery click () can only trigger event handlers for DOM 0 and event handlers registered through jQuery ...?

[Refresh:] This question is related to: what does jQuery click () do?

Click click jQuery () did not click?

The following code:

  <div id="oneDiv">
    some content
  </div>

  <p>
    <a href="http://www.google.com" id="clickme">Click Me</a>
  </p>

        [ ... ]

  onload = function() { 

    $('#clickme').click(function() {
      $('#oneDiv').css({border: '6px dotted #07d'})
    });

    document.getElementById('clickme').onclick = function() {
      document.getElementById('oneDiv').style.color = 'green';
    }

    document.getElementById('clickme').addEventListener("click", function() {
      document.getElementById('oneDiv').style.background = '#ffc';
    }, false);  // bubbling phase


    setTimeout(function() {
      $('#clickme').click();
    }, 3000);

  }

If you click on the link, the browser will be

1) change the border to 6px with a dotted blue
2) change the text inside the div so that it is green
3) change the background of the div to offwhite
4) go to www.google.com

but if you wait and enable the setTimeout () function, it will only do

$('#clickme').click(function() { })  
onclick = function() { ... }

he will not do addEventListenerone, and he will not follow the link. (IE 8 doesn't allow the addEventListenerway)

? jQuery click(), , ('click'), , DOM 0?

0
1

jQuery , javascript. , jQuery :

_replace

document.getElementById('clickme').onclick

$('#clickme').click(function {...});

_ replace

addEventListener("click"

_ by

live("click") or bind("click")

(. jQuery ).

_ :

document.getElementById('oneDiv').style.background = '#ffc';

_ by

$('#oneDiv').css('background-color','#ffc');

:

$(window).load(function() {....});

, , , jQuery ;)

: :

$(window).load(function() {
            $('#clickme').click(function() {
            $('#oneDiv').css({border: '6px dotted #07d'});
            $('#oneDiv').css('color','green');
            $('#oneDiv').css('background-color','#ffc');})

            setTimeout(function() {
                $('#clickme').click();
            }, 3000);

});
0

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


All Articles