Why doesn't the function work?

  • 0
    document.getElementsByTagName("option").onmousedown = function(e) {
    	if(e.button === 2) {
    		alert(2);
    	}
    };
    JavaScript Anonymous, Apr 11, 2019

  • 1 Answers
  • 0
    getElement s ByTagName (plural)


    You get an array, not a single item.



    Then it's like this:

    document.getElementsByTagName("option")[0].onmousedown =
    Anonymous

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