0
これは、HTMLでの私のコードです:追加(イベントを使用して)「タイトル」の要素に属性
<img id="test" src="https://blah">
これは私のjQueryのであり、それは動作します:
私は属性を追加するにはどうすればよい$(document).on('mouseover', 'img', function(e) {
}
この 'img'要素に?私はこれをしたい:
<img id="test" src="https://blah" title='test'>
は、私が試した:
e.attr('title', 'test');
e.prop('title', 'test');
this.attr('title', 'test');
$(this).attr('title', 'test');
this.prop...
ようにというように。 $(this)
はホバーされた画像を表し、この場合
$('img').hover(function() {
$(this).attr('title', 'test');
});
:
私はしたいと思いますが、私はそれが必要です。私はこの 'img'に関するデータを取得するためにこれを使用しています。 –
@SeattleAls私の更新答えを見てください。 – adrianbanks
'e.target.setAttribute( 'title'、 'test');'私はあなたの答えから私を助けました。しかし、私は '$(document).on( 'mouseover'、 'img'、function(e){' –