javascript - jquery anchor 检测和前置

标签 javascript jquery

在 anchor 内,这有效:

$(this).prepend('<span>This is the span content</span>');

当尝试执行 if href 等于时,它不起作用

$('a[href="http://www.google.com"]').prepend('<span>You have selected Google</span>');

最佳答案

我已经做了一个示例,没有发现任何错误。

<script>
$(function(){
    $("#btn1").click ( function() {
        $("a[href='http://www.google.com']").prepend ( "<span>You have selected Google</span>" );
    });
});
</script>
<a href="http://www.google.com">Click</a>
<button id="btn1">Click me</button>

<强> Working Demo

关于javascript - jquery anchor 检测和前置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2018249/

相关文章:

javascript - 我可以使用谷歌登录验证我的应用程序中的用户吗?

javascript - 重复使用代码,无需提交两次表单

javascript - typescript 库: Hide internal exports

javascript - jquery on 方法上的多个函数

javascript - 将缓冲区转换为字符串

javascript - 使用 jQuery 插入 HTML 的最简单方法

c# - 如何将 li 元素从一个列表移动到另一个列表

javascript - Count++ 和 -- 不起作用

javascript - 如果值小于指定,则禁用提交按钮

javascript - ReactJS - UseRef,而不是 useState,来替换 props