をクリックした要素のjQueryを取得:私がボタンを持っているのonclick機能を
<button id="my-button" type="button" onclick="action()">press me</button>
私は「アクション」機能では、ボタン(「マイボタン」)のIDを取得したいです。
私はそれを取得しようとしました:
var id = $(this).id;
var id = $(this).attr('id');
私は、DOMからオブジェクトを送信しようとした:
<button id="my-button" type="button" onclick="action(this)">press me</button>
、それは動作しませんでした...
をどのようにすることができます私はIDを取得?あなたはしかし、パラメータ
function action(elm) {
alert(elm.id)
}
<button id="my-button" type="button" onclick="action(this)">press me</button>
を受け入れる必要が