Hàm setAttribute gán thuộc tính cho 1 thẻ html trong javascript Run

Code: Html | Auth: 03cd82
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>https://zezo.dev</title>
</head>

<body>
    <h1 id="id1">Thực hành gán giá trị cho thuộc tính của thẻ </h1>

    <img src="https://zezo.dev/uploads/snvn.jpg" />

    <script>
        //1. khai báo biến để nhận phần tử html
        var objImg = document.querySelector('img'); // lấy phần tử img đầu tiên của trang html


        // 2. Gán giá trị cho thuộc tính SRC, hàm setAttribute không cần dùng biến thu giá trị

        objImg.setAttribute("src", 'https://zezo.dev/uploads/linux.png');
         
           // ok chạy thử xem nhé.

    </script>

</body>

</html>