상세 컨텐츠

본문 제목

[j쿼리]remove empty

카테고리 없음

by esoesmio 2023. 5. 24. 19:06

본문

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Title</title>
    <script src="https://code.jquery.com/jquery-3.7.0.min.js"></script>

    <style>
        table{
            border-collapse : collapse;
        }
        table,td,th{
            border: 1px solid black;
        }
    </style>
</head>
<body>
<table id = "tb1">
    <thead>
    <tr>
        <th>번호</th>
        <th>제목</th>
        <th>작성자</th>
    </tr>
    </thead>
    <tbody>
    <tr>
        <td>1</td>
        <td>게시글</td>
        <td>히히히</td>

    </tr>
    </tbody>
</table>

<table id = "tb2">
    <thead>
    <tr>
        <th>번호</th>
        <th>제목</th>
        <th>작성자</th>
    </tr>
    </thead>
    <tbody>
    <tr>
        <td>1</td>
        <td>게시글</td>
        <td>히히히</td>

    </tr>
    </tbody>
</table>


</body>



<script>
//1.empty() 하위 태그를 모두 삭제
$("#tb1").empty();

//2. remove() : 해당 태그 삭제
const timeout = setTimeout(()=>{
    $("#tb2").remove();
},2000)


</script>
</html>

댓글 영역