在 HTML 中我有这个:
<div id="content">
what is inside
</div>
<a title='content'>inside my link</a>
使用 JQuery,我想向 a 元素添加一个属性,其值是 a 元素的标题值中引用的元素的值。
我想过,但显然 $(this) 不是我想的那样:
$('a').attr('myNewAttribute', $('#' + $(this).attr('title')).text().trim());
myNewAttribute 为空