Why doesn't any event other than onclick work?

  • 0
    Already simplified does not work even in this form. I tried it with both a mouse and a touchpad.
    There is a div (empty with class, let's say content)
    function t9(){ console.log ('1'); }
    function t10(){ console.log ('2'); }
    
    document.querySelector('.content').onclick = t9;
    document.querySelector('content').ondblclick = t10;


    as a result, 1- appears in the console, 2 -not.
    I try another way, commenting out the first line ( document.querySelector ('. content'). onclick = t9; ), replacing the handler assignment with:
    document.querySelector('content').addEventListener ("dblclick", t10);

    And the silence is the same with other events. What to do ? How to check? Only one click event works.
    The code is written in VSC, Windows 10 system, Chrome browser and Edge.
    JavaScript Elizabeth Mosley, Sep 25, 2019

  • 2 Answers
  • 0
    function t9(){ console.log ('1'); }
    function t10(){ console.log ('2'); }

    var items = document.getElementsByClassName('content');

    for (var i = 0; i < items.length; i++) {
    items[i].addEventListener( 'click', function() { t9() } );
    items[i].addEventListener( 'dblclick', function() { t10() } );
    }




    with the entry function () {t9 ()} I'm not quite sure which is correct, because I don't practice JS, but I checked the code - it works
    Anonymous

  • 0
    Here is such an experiment, can anyone know what may be.

    https://youtu.be/4b233x0NFZE
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!