SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru tictike's Avatar
    Join Date
    Apr 2008
    Location
    Canada
    Posts
    863
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    jQuery wrap halfs of element children with different div

    With the following code, can some please explain how I can wrap paragraph 1 - 9 in a <div> and 10 - 17 in another div. I can write the code, I'm just not sure of the logic / program flow of what I'm trying to do.

    Thanks.

    Code HTML4Strict:
    <div id="mega">
    				<p>1</p>
    				<p>2</p>
    				<p>3</p>
    				<p>4</p>
    				<p>5</p>
    				<p>6</p>
    				<p>7</p>
    				<p>8</p>
    				<p>9</p>
    				<p>10</p>
    				<p>11</p>
    				<p>12</p>
    				<p>13</p>
    				<p>14</p>
    				<p>15</p>
    				<p>16</p>
    				<p>17</p>	
    			</div>

    desired outcome:

    Code HTML4Strict:
    <div id="mega">
    <div>
    	<p>1</p>
    	<p>2</p>
    	<p>3</p>
    	<p>4</p>
    	<p>5</p>
    	<p>6</p>
    	<p>7</p>
    	<p>8</p>
    	<p>9</p>
    </div>
    <div>
    	<p>10</p>
    	<p>11</p>
    	<p>12</p>
    	<p>13</p>
    	<p>14</p>
    	<p>15</p>
    	<p>16</p>
    	<p>17</p>	
    </div>
    </div>

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Get all the p elements into a jquery object
    filter some out, using filter() and a css selector like :lt(9)
    see wrappAll()

  3. #3
    SitePoint Guru tictike's Avatar
    Join Date
    Apr 2008
    Location
    Canada
    Posts
    863
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you. That's exactly what I needed.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •