You can try jQuery replaceWith()using the syntax of the callback function to extract the current contents of the span element and place it in a new anchor element.
() , :
function replaceWithAnchor(selector,url) {
$(selector).replaceWith(function() {
return $("<a></a>").attr("href",url).append($(this).contents());
});
}
replaceWithAnchor("span", "http://google.com");
: http://jsfiddle.net/cSZGr/1/
(. , , "span", , , - , .)
, , :
$("span").replaceWith(function() {
return $("<a></a>").attr("href","http://URL.com").append($(this).contents());
});
:
<span>I want this to be a link</span>
:
<a href="http://google.com">I want this to be a link</a>
P.S. .wrap(), span, , , , - .