DOM manipulation
Update text, HTML, classes and children without clobbering state.
What you will be able to do
- Use .text for untrusted strings.
- Use .html only for trusted markup.
- Use .append and .prepend to add content.
- Use .addClass, .removeClass and .toggleClass for state.
In plain English
jQuery’s .text sets text safely, .html parses markup and .append adds nodes. Prefer .text for user data. When replacing a list, preserve focus and selection where possible.
$('#status').text('Saved')
$('#list').append($('<li>').text('New lesson'))
$('#panel').toggleClass('is-open')Your turn
EasyAppend a list item
Append an li with the text "CSS" to #lessons.
JAVASCRIPT · starter
$('#lessons').append()Check your understanding before moving on.
Knowledge checkQuestion 1
Which method safely inserts plain text?
Select an answer to continue
Study tools
Make it yours.
Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.
Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign inFinished reading?
Lock in what you just learned.
0%
Mark this lesson complete to save your place and move one step closer to the certificate.