Finding which element is clicked in the DOM

前端 未结 3 810
迷失自我
迷失自我 2021-01-03 14:08

The question was asked to me in an interview.

How to find which element is clicked by the user in the DOM using JQuery or Javascript or Both?

NOTE: User can

3条回答
  •  孤街浪徒
    2021-01-03 14:17

    event.target sounds like what you're after.

    $('#id').click(function(e) {
        //e.target will be the dom element that was clicked on
    });
    

提交回复
热议问题