Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
freem
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Openai/69181628-34d0-8007-8e81-02401c649370
Add languages
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{DISPLAYTITLE:μ±λ₯ λΉκ΅ ν΄λμ€ μΈλΌμΈ}} ''This conversation was exported from ChatGPT''<ref>{{cite web|title=μ±λ₯ λΉκ΅ ν΄λμ€ μΈλΌμΈ|url=https://chatgpt.com/share/69181628-34d0-8007-8e81-02401c649370|publisher=ChatGPT|access-date=2025-11-15}}</ref> == gpt-5-1 == === User: 8. === # μ±λ₯ κ³ λ €: ν΄λμ€ vs μΈλΌμΈ μ€νμΌ β μ±λ₯ λμ λ°©μ (리νλ‘μ° μ λ°) # π ν΄λμ€μ μ€νμΌμ λ€λ£¨λ κ°μ₯ κ°λ ₯ν λ°©λ² β classList, style, κ·Έλ¦¬κ³ λ¦¬νλ‘μ°κΉμ§ 3 items.forEach(item => { item.style.backgroundColor = "yellow"; item.style.fontWeight = "bold"; }); β μ§μ μΈλΌμΈ μ€νμΌμ 루νλ§λ€ μ§μ = 리νμΈνΈ/리νλ‘μ° μ¦κ° β μ±λ₯ μ’μ λ°©μ /'' style.css ''/ .highlight { background-color: yellow; font-weight: bold; } items.forEach(item => { item.classList.add("highlight"); }); β ν΄λμ€ λ³κ²½μΌλ‘ λ λλ§ μ±λ₯ ν₯μ + μ½λ μ¬μ¬μ©μ± μ¦κ° μ΄κ² λ§λ λ§μ΄μΌ? λ΄κ° μκΈ°λ‘, λΈλΌμ°μ μμ μλ°μ€ν¬λ¦½νΈ μμ§μ μ±κΈμ°λ λκΈ° λλ¬Έμ μ΄λ€ λ°©μμΌλ‘ μ€ννλ μ μμ±λ€μ΄ λ€ μ μ©λκ³ λμ, 리νλ‘μ°/리νμΈνΈκ° λ°μνκΈ° λλ¬Έμ μ±λ₯μ μΌλ‘λ κ°μ κ±°λ‘ μΆμΈ‘λΌ === Assistant: κ²°λ‘ λΆν° λ§νλ©΄ βμΈλΌμΈ μ€νμΌ λ°λ³΅ μ μ©μ 리νλ‘μ°/리νμΈνΈκ° λ λ§μ΄ μΌμ΄λλ€βλ λ¬Έμ₯μ λλΆλΆμ κ²½μ° μ¬μ€μ΄ μλλ€. === κ²°λ‘ λΆν° λ§νλ©΄ βμΈλΌμΈ μ€νμΌ λ°λ³΅ μ μ©μ 리νλ‘μ°/리νμΈνΈκ° λ λ§μ΄ μΌμ΄λλ€βλ λ¬Έμ₯μ λλΆλΆμ κ²½μ° μ¬μ€μ΄ μλλ€. λΉμ μ΄ λ§ν λΈλΌμ°μ μ λ λλ§ μ΅μ ν(λ μ΄μμ λ°°μΉ / νλ¬μ λλ μ΄) λλΆμ loop μμμ styleμ μ¬λ¬ λ² μ€μ νλ€κ³ ν΄μ λ§€λ² λ¦¬νλ‘μ°κ° μΌμ΄λλ κ²μ μλλ€. === β μ νν μ 리 === ==== 1) JS μ€νκ³Ό λ λλ§μ λΆλ¦¬λμ΄ μμ ==== * JS μμ§μ μ±κΈμ€λ λμ§λ§, λ λλ§ μμ§μ JS μ€νμ΄ λλ νμμΌ λ μ΄μμ/νμΈνΈλ₯Ό μ§νν¨. * λ°λΌμ μλ μ½λμ²λΌ 루ν μμμ 10λ² style μ€μ ν΄λ, JS μ€ν μ€κ°μ λ°λ‘λ°λ‘ λ μ΄μμμ΄ μΌμ΄λμ§ μμ. <syntaxhighlight lang="js">items.forEach(item => { item.style.backgroundColor = "yellow"; item.style.fontWeight = "bold"; }); </syntaxhighlight> β‘ λ λλ§ λ¨κ³μμ ν λ²μ λ°°μΉ μ²λ¦¬λ¨. β‘ μ¦, μΌκ΄μ μΌλ‘ βμ€νμΌ λ³κ²½λ¨ β λ μ΄μμ νμβλΌκ³ νλκ·Έλ§ νμλ¨. ==== 2) 리νλ‘μ°λ₯Ό βμ¦μβ μΌμΌν€λ κ²μ βμ½κΈ° β μ°κΈ°β μμ μΆ©λμΌ λλΏ ==== μ: <syntaxhighlight lang="js">item.style.width = "100px"; const w = item.offsetWidth; // κ°μ λ μ΄μμ λ°μ! item.style.height = "200px"; </syntaxhighlight> μ΄λ° κ²½μ°μλ§: * style λ³κ²½ β layout pending * offsetWidth μ½κΈ° β layout κ°μ νλ¬μ μ΄ ν¨ν΄μ΄ λ°λ³΅λλ©΄ μ±λ₯μ΄ λλΉ μ§. κ·Έλ¬λ μ§λ¬Έμ μμμ²λΌ: <syntaxhighlight lang="js">item.style.backgroundColor = "yellow"; item.style.fontWeight = "bold"; </syntaxhighlight> λ λ€ μ°κΈ°(Write) λμμ΄λ―λ‘ κ°μ λ μ΄μμμ΄ μμ. ==== 3) κ·Έλ λ€λ©΄ classList μ°λ κ² λ λΉ λ₯΄λ? ==== μ±λ₯μ μ°¨μ΄λ βλ λλ§ λΉμ©βμ΄ μλλΌ βJS μ€ν λΉμ©βμ κ°κΉλ€. ===== ν΄λμ€ λ³κ²½ ===== * JS λ¨μμ 1λ²μ class λ³κ²½ * CSS λ£° λ§€μΉ λ€μ μν (μ€νμΌ κ³μ° λΉμ© μ½κ° μ¦κ°) ===== μΈλΌμΈ μ€νμΌ λ³κ²½ ===== * JS λ¨μμ μμ± 2λ² λ³κ²½ * CSS λ£° λ§€μΉμ μ€νλ € λ¨μν¨ (μΈλΌμΈ μ€νμΌμ΄ specificity μ΅μμ) ===== μ±λ₯ μ°¨μ΄λ λ―Έλ―Έν¨ ===== λͺμ~λͺλ°± κ° DOM λ ΈλκΉμ§λ class μΆκ° vs μΈλΌμΈ μ€νμΌ μ°¨μ΄λ μ¬μ€μ 0μ κ°κΉμ. μΈ‘μ νλ©΄ classList.add 1ν < style 2ν μ μ© μ λμ μ°¨μ΄λ§ λ¨. === 4) κ·ΈλΌ μ "ν΄λμ€λ₯Ό μ°λ κ²μ΄ μ±λ₯μ μ’λ€"λ λ§μ΄ λ§μ΄ νΌμ‘λ? === μ νν μ΄μ λ λ€μκ³Ό κ°μ: ===== β CSS κ΄λ¦¬ μΈ‘λ©΄μμ λ μ’κΈ° λλ¬Έ (μ§μ§ μ΄μ ) ===== * μ¬μ¬μ©μ±μ΄ μλ±ν μ’μμ§ * μ μ§λ³΄μ λΉμ© κ°μ * ν° νλ‘μ νΈμμ μ€νμΌ κ΄λ¦¬ μ΅μ ν ===== β‘ λ§μ μΈλΌμΈ μ€νμΌμ style attributeλ₯Ό κ³μ λ°κΎΈλ―λ‘ DOM size μ¦κ° ===== μ±λ₯μ΄λΌκΈ°λ³΄λ€ DOM λ©λͺ¨λ¦¬ footprint λ¬Έμ . ===== β’ νΉμ μν©μμλ λ μ΄μμ μ°κΈ° μ΅μ νκ° κΉ¨μ§ μ μμ ===== * λ§€μ° λ§μ inline writeκ° DOM μ¬λ¬ κ³³μ λΆμ°λμ΄ μμΌλ©΄ λΈλΌμ°μ μ λ μ΄μμ λ°°μΉμ΄ λΉν¨μ¨μ μΌλ‘ μλν κ°λ₯μ± νμ§λ§ μ΄λ λ§€μ° edge case. === π« μλͺ»λ μ£Όμ₯ (μ μ ) === : μΈλΌμΈ μ€νμΌμ 루νλ§λ€ μ§μ νλ©΄ 리νλ‘μ°/리νμΈνΈκ° λ§€λ² λ°μνλ€. β μΌλ°μ μΌλ‘ νλ¦° λ§. β νλ λΈλΌμ°μ λ layout/paintλ₯Ό JS μ€ν μ€μ λ°μμν€μ§ μμ. === π’ μ¬λ°λ₯Έ κ²°λ‘ === ===== β μΌλ° μν© β μ±λ₯μ κ±°μ κ°λ€ ===== * classList.add β 1νμ style change * inline style 2ν β 2νμ style change β‘ λ λλ§μ λͺ¨λ JS μ΄νμ λ°°μΉλ¨ β 리νλ‘μ° νμλ λμΌ β‘ UI μ°¨μ΄λ λ―Έλ―Έ ===== β μ€μ λ‘ classκ° λ μ’μ μ΄μ ===== * μ μ§λ³΄μμ± * μ¬μ¬μ©μ± * κΉλν HTML * μν λ³ν κ΄λ¦¬κ° μ¬μ μ¦, μ±λ₯ λλ¬Έμ classκ° λ μ’λ€κ³ λ§νλ 건 λ무 λ¨μνλ μ€λͺ μ΄κ³ , μ€μ μ΄μ λ βκ΄λ¦¬ μΈ‘λ©΄βμ΄ ν¨μ¬ ν¬λ€. μνλ©΄ λ€μκ³Ό κ°μ λ΄μ©λ λ μ€λͺ ν΄μ€ μ μμ΄: * βμ νν μΈμ 리νλ‘μ°/리νμΈνΈκ° λ°μνλκ°β * βstyle.writeμ style.read μΆ©λ ν¨ν΄(W-R-W Anti-pattern)β * βμ±λ₯ μΈ‘μ μ€ν μ½λ(JSPerf μ€νμΌ)β * βReact/Virtual DOMμμ μ inline styleμ΄ λ λ리λ€κ³ μ¬κ²¨μ§λκ°?β == References == <references /> [[Category:ChatGPT Shares]] [[Category:openai]]
Summary:
Please note that all contributions to freem are considered to be released under the Creative Commons Attribution-ShareAlike 4.0 (see
Freem:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Cite web
(
edit
)
Module:Citation/CS1
(
edit
)
Module:Citation/CS1/COinS
(
edit
)
Module:Citation/CS1/Configuration
(
edit
)
Module:Citation/CS1/Date validation
(
edit
)
Module:Citation/CS1/Identifiers
(
edit
)
Module:Citation/CS1/Utilities
(
edit
)
Module:Citation/CS1/Whitelist
(
edit
)
Module:Citation/CS1/styles.css
(
edit
)