jQuery — Set Content
Setting Text
$("p").text("New paragraph text");
Setting HTML
$("div").html("<strong>Bold</strong> content");
Setting Val
$("input").val("Hello World");
$("select").val("option2");
Setting Attributes
$("img").attr("src", "new-photo.jpg");
$("a").attr("href", "https://example.com");
Setting Multiple Attributes
$("img").attr({
src: "new-photo.jpg",
alt: "New photo",
title: "Photo title"
});
Setting Properties
$("input:checkbox").prop("checked", true);
$("input:text").prop("disabled", false);
Setting CSS Inline
$("h1").css("color", "red");
$("h1").css({
color: "red",
"font-size": "24px",
"background-color": "#f0f0f0"
});
Practical Form Example
// Set multiple form values
$("#name").val("John");
$("#email").val("john@example.com");
$("#country").val("USA");
Mini Practice
- Set text on a paragraph
- Set HTML with bold and links
- Set multiple attributes at once
- Set CSS styles inline
Up Next
Continue with Add Elements — inserting new content into the DOM.
Related Topics
Frequently Asked Questions about Set Content
What is Set Content in jQuery?
Set Content is a fundamental concept in jQuery. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn Set Content?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Set Content.
Why is Set Content important in jQuery?
Set Content is essential for jQuery development. Understanding this concept will help you write better code and solve real-world problems more effectively.