๐Ÿ’ปCoding/๐Ÿ“˜ JavaScript

JavaScript _HTML ์ปจํ…์ธ ๋ฅผ ๋ณ€๊ฒฝํ•˜๊ธฐ

์Œ์€์‘ 2021. 8. 26. 14:23
728x90
๋ฐ˜์‘ํ˜•

JavaScript _HTML ์ปจํ…์ธ ๋ฅผ ๋ณ€๊ฒฝํ•˜๊ธฐ

JavaScript
Q : ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋กœ html์—์„œ ์ž‘์„ฑํ•œ ๋‚ด์šฉ์„ ๋ฐ”๊พธ๊ณ  ์‹ถ์„๋•Œ?

>> ์•„์ด๋””(id)๋ฅผ ์ด์šฉํ•ด ์„ ํƒ getElementById() ๋ฉ”์†Œ๋“œ๋Š” ์•„์ด๋””๋ฅผ ์ด์šฉํ•˜์—ฌ HTML ์š”์†Œ๋ฅผ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

 

[ ์ž‘์„ฑ๋ฐฉ๋ฒ• ]

document.getElementById('text1').innerHTML="๋‚ด์šฉ๋ฐ”๊พธ๊ธฐ";
[ ํ•ด ์„ ]
→ ์›น๋ฌธ์„œ . Id text1์ธ HTML ์š”์†Œ ๊ฐ€์ ธ์™€ . ๋‚ด๋ถ€๊ธ€์ž = "๋ฐ”๊พธ๊ณ  ์‹ถ์€ ๋‚ด์šฉ์ ๊ธฐ" ; 

 

[ ์ฝ”๋“œ ์ž‘์„ฑ ]

<!DOCTYPE html>
<html lang="ko">
<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>js_getElementById</title>
    <style>
        #text1 { color: red;}
    </style>
</head>
<body>
    <p id="text1">CSS ์•„์ด๋”” ์„ ํƒ์ž</p>

    <script>
        document.getElementById('text1').innerHTML="๋‚ด์šฉ๋ฐ”๊พธ๊ธฐ";
    </script>
</body>
</html>

 

 

๐Ÿ“Œ javascript๋ฅผ ๋„ฃ์–ด์„œ ์‹ค์ œ๋กœ ๊ธ€์ž ๋‚ด์šฉ์ด ๋ฐ”๋€Œ๋Š”์ง€ ํ™•์ธํ•ด๋ณผ๊นŒ์š”?

[์™ผ์ชฝ : ํฌ๋กฌ ์‹คํ–‰ ํ™”๋ฉด] - [ VScode : ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ์ž‘์„ฑ]

 

728x90
๋ฐ˜์‘ํ˜•