How to create a div element using jQuery and add it to the page?
Hello everyone! I just started learning jQuery and I can't figure out how to create new elements on the page. I keep getting confused with the syntax.
I need to dynamically add blocks with information to the site. I know that in pure JavaScript I can create a div using `document.createElement('div')`, and then add it using `appendChild`. But how can I do this more simply with jQuery?
I tried writing something like `$('
')`, but I don't understand how to then insert this div into the right place on the page. For example, I have a container:
```html
```
And I need to add a new block with class `new-block` inside it, which will contain a heading and a paragraph. I tried to do this:
```javascript
var newDiv = $('
Current text
');
new
No answers yet.
Log in to leave an answer
Blogs
Kotlin vs Python for Backend: What to Choose in 2025?
Top 10 Swift Frameworks for Web Development in 2025