Skip to content
Advertisement

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>

Advertisement

Answer

You can get the attribute by jQuery

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

JS :

$(document).on('click', 'a', function() { 
    alert(id); 
}); 
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement