Passing data to a jQuery click() function

后端 未结 5 2063
独厮守ぢ
独厮守ぢ 2021-01-01 21:21

I have a simple span like so

Remove

This span is within a table, each row has a remo

5条回答
  •  爱一瞬间的悲伤
    2021-01-01 22:05

    If you insist on using old-school HTML 4.01 or XHTML:

    $('.removeAction').click(function() {
     // Don’t do anything crazy like `$(this).attr('id')`.
     // You can get the `id` attribute value by simply accessing the property:
     this.id;
     // If you’re prefixing it with 'my' to validate as HTML 4.01, you can get just the ID like this:
     this.id.replace('my', '');
    });
    

    By the way, in HTML5, the id attribute can start with a number or even be a number.

    Then again, if you’re using HTML5 anyway, you’re probably better off using custom data attributes, like so:

    Remove
    

提交回复
热议问题