javascript - How to add a span inside a link tag with jQuery? -
this question has answer here:
- add span tag within anchor in jquery 3 answers
i have code here in html:
<a class="cta" href="url" target="_blank">text</a>
what try achieve add span
tag inside link tag, this:
<a class="cta" href="url" target=_"blank"><span>text</span></a>
i tried prepend seems not work case…
the .html( function )
method changing html content of element. current html content of element setted in html
variable in function can set in new added child.
$("a.cta").html(function(i, html){ return "<span>"+ html +"</span>"; });
span { color: red }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <a class="cta" href="url" target="_blank">text</a> <a class="cta" href="url" target="_blank">text 2</a>
Comments
Post a Comment