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
Mary-Kate OlsenOriginal
2024-11-29 17:29:11334browse

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');

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!

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