[英]Adding a span tag between the text of anchor tag using jquery
How would you add a span tag before the text inside a hyperlink? 如何在超链接中的文本之前添加span标签? Right now, I'm using this:
现在,我正在使用这个:
<script type="text/javascript">
$("a").before('<span class="k-icon k-add"></span>');
</script>
I tried the above code but the required span is coming before the anchor tag 我尝试了上面的代码,但是所需的跨度在锚标记之前
<span class="k-icon k-add"></span><a href="some page">Add</a>
I need the link to look like this when it is parsed: 解析后,我需要链接看起来像这样:
<a href="some page"><span class="k-icon k-add"></span>Add</a>
Any ideas? 有任何想法吗?
使用prepend在元素的开头添加一些内容:
$("a").prepend('<span class="k-icon k-add"></span>');
I suggest you to add icons not with js but with pseudo elements in css 我建议您在CSS中不使用js而是使用伪元素添加图标
It will be something like this: 将会是这样的:
a.k-icon.k-add:before {
width: 10px;
height: 10px;
background: #ccc;
content: '';
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.