[英]Added text before an anchor tag
I would like to add some text just before the anchor tag I click on. 我想在点击的锚标记之前添加一些文本。 The following adds the text to the actual anchor tag itself: 以下内容将文本添加到实际的锚标记本身:
$(document).ready(function(){
$(".none_standard_links").live('click', function(event)
{
event.preventDefault();
$(this).prepend("test");
});
});
the above gives me html as shown below: 上面给了我html,如下所示:
Before the link is clicked 点击链接之前
<a href="#" class="none_standard_links">link one</a>
After the link is clicked 单击链接后
<a href="#" class="none_standard_links">testlink one</a>
What I want is this: 我想要的是:
test<a href="#" class="none_standard_links">link one</a>
Try using the before() function. 尝试使用before()函数。 Should be what you need 应该是你所需要的
$(this).before("test");
Try using .before
: 尝试使用.before
:
$(this).before('something');
You can use .insertBefore
, but it is slightly more verbose since you have to explicitly create a text node: 您可以使用.insertBefore
,但是由于您必须显式创建一个文本节点,因此它有点冗长:
$(document.createTextNode("hello")).insertBefore("a");
尝试改用before()
$(this).before("test");
使用$.before
:
$(this).before("test");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.