Passing data to a jQuery click() function

Posted by jakenoble on Stack Overflow See other posts from Stack Overflow or by jakenoble
Published on 2010-05-10T09:55:27Z Indexed on 2010/05/10 10:04 UTC
Read the original article Hit count: 161

Filed under:
|
|
|

Hi

I have a simple span like so

<span class="action removeAction">Remove</span>

This span is within a table, each row has a remove span.

And then I call a URL using AJAX when that span is clicked. The AJAX event needs to know the ID of the object for that row? What is the best way of getting that ID into the click function?

I thought I could do something like this

<span class="action removeAction" id="1">Remove</span>

But an ID should not start with a number? Right? Then I thought I could do

<span class="action removeAction" id="my1">Remove</span>

Then just strip the 'my' part from the ID, but that just seems Yuk!

Below is my click event and where my AJAX event is.

<script type="text/javascript" language="text/javascript">

$(document).ready(function()
{

    $(".removeAction").click(function()
    {
        //AJAX here that needs to know the ID            
    }
});

</script>

I am sure there is a nice way of doing this?

Thanks. Jake.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about function