附加到元素时从元素的标题属性获取文本
我有一个函数,可以在带有 .help
类的所有元素之后附加 div (帮助图标)。
jQuery().ready(function() {
jQuery('.help').append('<div class="mark"></div>');
});
我需要向该函数添加什么才能从 .help
元素的 title 属性获取信息?
我是脚本新手。
I have function which append div (help icon) after all element with .help
class.
jQuery().ready(function() {
jQuery('.help').append('<div class="mark"></div>');
});
What do I need to add to that function to get information from title attribute of .help
element?
I'm new in scripting.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
利用
append()
也可以接受一个函数来创建要附加的 HTML 字符串:Utilizing the fact that
append()
can also accept a function that will create the HTML string to append:我想这就是你想要的:
});
I think this is what you want:
});
我认为您正在寻找类似的内容:
这将为每个帮助元素添加一个
div.mark
并将该标记的标题设置为父帮助的标题。I think you are looking for something like this:
This will add a
div.mark
to each help element and set the title of the mark to be the title of the parent help.尝试使用 attr 函数:
Try to use the attr function: