Check which element has been clicked with jQuery

前端 未结 7 673
天命终不由人
天命终不由人 2020-12-24 07:10

I am trying to use an \'if\' statement to determine which element was clicked.

Basically I am trying to code something along the lines of:

if (the el         


        
7条回答
  •  -上瘾入骨i
    2020-12-24 07:36

    Answer from vpiTriumph lays out the details nicely.
    Here's a small handy variation for when there are unique element ids for the data set you want to access:

    $('.news-article').click(function(event){    
        var id = event.target.id;
        console.log('id = ' + id); 
    });
    

提交回复
热议问题