简体   繁体   中英

How can I make a browser record the click like Facebook does?

This is my current project. I need to record the current state of an <a> and I get it with PHP, I must be missing something. I have tried to follow the .on() example, but the problem is that when I use it, it is not capturing the click event.

Can someone help please?

 $(document).on('click', 'a', function() { alert($(this).attr('id')); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <a href="#" id="current" name="text1">a</a> <a href="#" id="current" name="text2">b</a> <a href="#" id="current" name="text3">c</a> <a href="#" id="current" name="text4">d</a>

You can get the attribute by jQuery

var id = $(this).attr('id'); 

JS:

$(document).on('click', 'a', function() { 
    alert(id); 
}); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM