www.webdeveloper.com
Results 1 to 3 of 3

Thread: Can't figure out how to wrap div tags outside root element

  1. #1
    Join Date
    Mar 2010
    Location
    Finland
    Posts
    77

    Can't figure out how to wrap div tags outside root element

    I'm trying to get some div tags to wrap around 3 elements, but my jQuery code only gets me wrapping 2. Here is the example...
    http://jsbin.com/ihucel/9/edit

    Which outputs...
    HTML Code:
    <img title="Title Caption" alt="Alt Caption" class="captionImg" src="http://static.jquery.com/files/rocker/images/logo_jquery_215x53.gif">
    <div class="imgWrapper">
        <br>
        <span class="imgCaption">Title Caption</span>
    </div>
    I would need it to also wrap the image tag like so...
    HTML Code:
    <div class="imgWrapper">
        <img title="Title Caption" alt="Alt Caption" class="captionImg" src="http://static.jquery.com/files/rocker/images/logo_jquery_215x53.gif">
        <br>
        <span class="imgCaption">Title Caption</span>
    </div>
    Any ideas how to do this?

    Thanks in advance

  2. #2
    Join Date
    Sep 2008
    Location
    Akron, OH
    Posts
    1,105
    Here's a way you can do it! You just create the container, add it to the DOM, then append the content.

    http://jsbin.com/ihucel/11/edit
    I'm always up for networking with fellow web professionals. Connect with me on LinkedIn if you like!

  3. #3
    Join Date
    Mar 2010
    Location
    Finland
    Posts
    77
    Oww, I don't believe I didn't realise that! I was reading through those very functions as I was trying to figure out that problem. It just didn't occur to me to create the wrapper first. Thanks.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles