我有这样的HTML:
<a href="#">
<span>children</span>
</a>
<button>click</button>
我想删除<a>
但请保留<span>
。我怎么能这样做?
$('button').on('click', function(){
/* to remove the link, but not the span */
});
答案 0 :(得分:1)
我会做类似的事情:
$a = $("a")
$a.replaceWith($a.children());
答案 1 :(得分:0)
$('button').on('click', function(){
/* to remove the link, but not the span */
var inner_html = $("#my_anchor").html();
$("#parent").html(inner_html)
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="parent">
<a href="#" id="my_anchor">
<span>children</span>
</a>
</div>
<button>click</button>
&#13;