Home > Web Front-end > JS Tutorial > How to Create a Div Element with jQuery?

How to Create a Div Element with jQuery?

Mary-Kate Olsen
Release: 2024-11-29 17:29:11
Original
405 people have browsed it

How to Create a Div Element with jQuery?

Creating a div Element in jQuery

Question: How do you generate a div element using jQuery?

Answer:

As of jQuery version 1.4, you can assign attributes to a self-contained element using the following syntax:

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

This syntax is documented in the jQuery documentation. Additional examples can be found in the jQuery blog post "jQuery 1.4 Released: The 15 New Features you Must Know."

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

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template