jQuery unwrap() remove the wrapper element and keep the text content

Description

jQuery unwrap() remove the wrapper element and keep the text content

View in separate window

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Remove Wrapper Element</title>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
    $(document).ready(function(){
        $("button").click(function(){
            $("p").find("a.link").contents().unwrap();
        });//from   ww w . j  ava  2 s. c  o m
    });
</script>
</head>
<body>
    <p>test <b>bold</b> test <span>span</span> 
    <a href="#" class="link">this link</a> test.</p>
    <button type="button">Remove Link</button>
</body>
</html>



PreviousNext

Related