Solved

wrapping dynamically in a div

Posted on 2014-07-17
2
294 Views
Last Modified: 2014-07-18
I have 2 divs next to each other.
div class=space
div class=space

how can i use jquery to add a wrapper around both div's that use selector space?
0
Comment
Question by:rivkamak
  • 2
2 Comments
 
LVL 2

Expert Comment

by:c l
ID: 40202955
give this a shot:

$( ".space" ).wrap( "<div class='new'></div>" );

Open in new window


more info on the wrap() function - http://api.jquery.com/wrap/
0
 
LVL 2

Accepted Solution

by:
c l earned 500 total points
ID: 40202966
sorry, i mis-read your question, you want it wrapped around BOTH divs, so use this instead:

$( ".space" ).wrapAll( "<div class='new' />");

Open in new window


more info on wrapAll() function - http://api.jquery.com/wrapall/
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

806 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question