- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to wrap first few items in div using jQuery?
To wrap first few items in div, use the lt selector and to wrap, use the wrapAll() method. You can try to run the following code to learn how to wrap first few list items in div using jQuery −
Example
<html> <head> <title>jQuery wrap() method</title> <script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function() { $('ul.myclass > li:lt(4)').wrapAll('<div class="demo"></div>') }); </script> <style> .demo { border: 3px dashed blue; margin: 5px; } </style> </head> <body> <ul class="myclass"> <li>India</li> <li>US</li> <li>UK</li> <li>Australia</li> <li>Bangladesh</li> <li>Nepal</li> <li>Bhutan</li> </ul> </body> </html>
- Related Articles
- How to wrap tables with div element using jQuery?
- How to wrap two adjacent elements in a containing div using jQuery?
- How to wrap and unwrap HTML control with a div dynamically using jQuery?
- How to duplicate a div using jQuery?
- How to create div dynamically using jQuery?
- How to print div content using jQuery?
- How to load a page in div using jQuery?
- How to scroll to element in horizontal div using jQuery?
- How to toggle a div visibility using jQuery?
- How to replace innerHTML of a div using jQuery?
- How to copy the content of a div into another div using jQuery?
- Wrap flex items in Bootstrap
- How to wrap multiple divs in one with jQuery?
- How to get the value of div content using jQuery?
- How to replace only text inside a div using jQuery?

Advertisements