Home >Web Front-end >JS Tutorial >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!