document api 실습
2022. 1. 30. 12:18ㆍksmart_html_css_js/HTML실습
728x90
1.
버튼을 클릭 시 해당 버튼의 행이 제거 될 수 있도록 하시오.
<table border="1">
<tbody>
<tr>
<td>제목</td>
<td><button type="button" class="tr-remove">제거</button></td>
</tr>
<tr>
<td>제목</td>
<td><button type="button" class="tr-remove">제거</button></td>
</tr>
</tbody>
</table>
1. 답
<script type="text/javascript">
var btn=document.querySelectorAll('.tr-remove');
for(var i=0;i<btn.length;i++){
btn[i].onclick=function(){
this.parentElement.parentElement.remove();
}
}
</script>
728x90
'ksmart_html_css_js > HTML실습' 카테고리의 다른 글
html 요소 이벤트 - form 실습 (0) | 2022.01.30 |
---|---|
CSS 가상 선택자 활용 실습_CSS (0) | 2021.12.16 |
CSS 가상 선택자 실습_CSS (0) | 2021.12.15 |
CSS 속성 종류 및 float 실습_CSS (0) | 2021.12.15 |
HTML실습CSS 선택자 및 CSS 속성 종류 실습_CSS (0) | 2021.12.15 |