【发布时间】:2016-11-22 14:12:55
【问题描述】:
我有以下 html 元素:
<a href="#" id="pinterest" alt="PINTEREST">
<img alt="PINTEREST" title="PINTEREST" src="image.png" class="icon">
</a>
我需要将title 属性值从“pinterest”更改为“联系我们”,当用户将鼠标悬停在上述图片上时,它会用作工具提示。
我已经进行了一些搜索,但我认为它不能用 CSS 完成(除了可能使用 :before 或 :after 伪元素?),所以我现在正在尝试使用 jQuery。
我的 jQuery 看起来像这样:
jQuery(document).ready(function($) {
$('#pinterest img').attr( 'title', 'Contact Us' );
)};
但它不起作用。
我注意到我的 jQuery 版本是 1.11.3,如果它是相关的(我了解了 prop 用于更高版本)
谢谢。
【问题讨论】:
-
您的
jquery版本应该无关紧要。您能否确认没有任何控制台错误? -
这是一个 wordpress 设置。我看到开发人员工具>控制台显示以下内容:
SyntaxError: expected expression, got ')'[Learn More]GET http://.../wp-content/themes/wp_oswad_market-child/images/media/bg-footer.jpg [HTTP/1.1 404 Not Found 1155ms]JQMIGRATE: Migrate is installed, version 1.4.1 jquery-migrate.min.js:2:542 This site appears to use a scroll-linked positioning effect. This may not work well with asynchronous panning; see https://developer.mozilla.org/docs/Mozilla/Performance/ScrollLinkedEffects for further details and to join the discussion on related tools and features! -
感谢您的建议。就是我用括号交换了花括号,正如您在下面标记的答案中看到的那样。但有趣的是,我没有看到控制台对此给出错误。
-
您粘贴的上述错误来自
console,这意味着您在console中遇到了该错误。我在为您准备Demo时发现了这个错误,但我认为您错过了该部分复制粘贴代码时..快乐编码.. :)
标签: jquery html attributes tooltip title