Reputation: 1
How would you add a span tag before the text inside a hyperlink? 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?
Upvotes: 0
Views: 3226
Reputation: 2425
I suggest you to add icons not with js but with pseudo elements in css
It will be something like this:
a.k-icon.k-add:before {
width: 10px;
height: 10px;
background: #ccc;
content: '';
}
Upvotes: 0
Reputation: 382150
Use prepend to add some content at the start of your element :
$("a").prepend('<span class="k-icon k-add"></span>');
Upvotes: 3