Home >Web Front-end >JS Tutorial >How to Create Div Elements Using jQuery?

How to Create Div Elements Using jQuery?

Barbara Streisand
Barbara StreisandOriginal
2024-12-07 13:12:14383browse

How to Create Div Elements Using jQuery?

Creating Div Elements with jQuery

Question: How do I use jQuery to create a "div" element?

Answer: From jQuery 1.4 onward, you have the ability to assign attributes to self-contained elements as follows:

jQuery('<div>', {
    id: 'some-id',
    class: 'some-class some-other-class',
    title: 'now this div has a title!'
}).appendTo('#mySelector');

Documentation:

  • [jQuery documentation](https://api.jquery.com/element/)

Examples:

  • [jQuery 1.4: 15 New Features You Should Know](https://www.sitepoint.com/jquery-1-4-released-the-15-new-features-you-must-know/)

The above is the detailed content of How to Create Div Elements Using jQuery?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn