I have the html
<div id=1>
<span id=2></span>
</div>
<div id=3>
</div>
I'm trying to replace span
with a
and use the anchor to .toggle()
<div id=3>
$('#2').replaceWith(function(){
return $("<a id=\"2\" href=\"#\" />").append($(this).contents());
});
This works at turning the span to an anchor, but when I try to chain a click function .toggle()
, it refuses to toggle.
$('#2').replaceWith(function() {
return $("<a id=\"2\" href=\"#\" />").append($(this).contents());
}).click(function() {
$('#3').toggle();
return false;
});
The click function .toggle()
works if I remove .replaceWith()
.