πŸ“innerText vs textContent

10_2pangΒ·2023λ…„ 6μ›” 4일
0

βš½οΈνŠΈλŸ¬λΈ”μŠˆνŒ…

λͺ©λ‘ 보기
8/94
post-thumbnail

μ—…λ‘œλ“œμ€‘..

πŸ‘¨β€πŸ’»Β μ‚¬κ±΄


  • 두가지 μ „λΆ€ 같은 μ²˜λ¦¬κ°€ λ˜λŠ”κ²ƒ 같은데, ꡳ이 λ”°λ‘œ μ‚¬μš©ν•˜λŠ” 이유λ₯Ό λͺ°λžλ‹€.
    <p id="txtP">
        hello
    </p>
    console.log(txtP.textContent); // hello  
    console.log(txtP.innerText); // hello

βœ…Β ν•΄κ²°


  • textContent λŠ” λ”°λ‘œ λ Œλ”λ§μ„ κ±°μΉ˜μ§€μ•Šκ³  λ‚˜νƒ€λ‚΄κ³  , innerTextλŠ” ν•œλ²ˆ λ Œλ”λ§μ„ κ±°μ³μ„œ μš°λ¦¬κ°€ λ³Ό 수 μžˆλŠ” λ‚΄μš©λ§Œμ„ ν‘œμ‹œν•΄ μ€λ‹ˆλ‹€. ( 쑰금 더 λΉ λ₯Έ νŽ˜μ΄μ§€ λ Œλ”λ§μ„ μœ„ν•΄μ„  textContent λ₯Ό μš°μ„ μ μœΌλ‘œ μ‚¬μš© ν•  ν•„μš”κ°€ 있음 )
<p id="txtP">
    hell<br>o
    <span style="display: none">hello</span> 
</p>
console.log(txtP.textContent); // hello 
															//	hello  
console.log(txtP.innerText); // hell
														//     o

πŸ’­Β κ°œμ„ 


  • 상황에 λ§žλŠ” λͺ…λ Ήμ–΄λ₯Ό μ‚¬μš©ν•΄μ•Ό ν•œλ‹€.
profile
μ£Όλ‹ˆμ–΄ ν”„λ‘ νŠΈμ—”λ“œ 개발자 이광렬 μž…λ‹ˆλ‹€ 🌸

0개의 λŒ“κΈ€