-3

I had my HTML like this.

<ul>
   <li><a href="#" id="abc"></a></li>
   <li><a href="#" id="bca"></a></li>
   <li><a href="#" id="cab"></a></li>
   <li><a href="#" id="acb"></a></li></ul>

when the user clicks on a particular link its id should be passed to an ajax script without using an onclick() function in markup HTML.Can it be achieved using the same anchor elemnt?? Thanks in advance.

2 Answers2

2

using jquery click event

  $("ul li a").click(function(e){
    e.preventDefault();
    var id = this.id;
// call your ajax code

    });

Bind an event handler to the "click" JavaScript event, or trigger that event on an element.

Sudharsan S
  • 15,336
  • 3
  • 31
  • 49
Balachandran
  • 9,567
  • 1
  • 16
  • 26
-1
$("ul li a").click(function(e){
var anchorid = $(this).attr('id');
alert(id);
e.preventDefault();
// call your ajax code

});

You will get id in anchorid variable.