attribute

유석현(SeokHyun Yu)·2022년 11월 16일
0

JavaScript

목록 보기
26/44
post-thumbnail
<!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>Document</title>
    </head>
    <body>
        <a id="target" href="http://naver.com">link</a>
        <script>
            let t = document.getElementById("target");
            console.log(t.getAttribute("href")); //http://naver.com

            t.setAttribute("title", "NAVER"); // title 속성 설정
            console.log(t.hasAttribute("title")); // true

            t.removeAttribute("title"); // title 속성 제거
            console.log(t.hasAttribute("title")); // false
        </script>
    </body>
</html>
profile
Backend Engineer

0개의 댓글