Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9258111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:18:46+00:00 2026-06-18T12:18:46+00:00

for given tag I need to wrap it with quite a few elements. So

  • 0

for given tag I need to wrap it with quite a few elements.
So that user can put

<img src="img.gif" >

but outcome would be

<div class="total">
    <div class="cover">
        <div class="crop">
            <img src="img.gif" alt> 
        </div>
        <div class="hover">
            <div class="peel">
                <div class="links">
                    <a href="#">FB</a>
                </div>

            </div>
        </div>
    </div>
</div>

So i decided to make it into jQuery plugin. And here is piece of it

(function($) {
$.fn.peel = function(options) {
    var defaults = {};
    var settings = $.extend({},defaults, options);

    return this.each(function() {
        $(this).load(function() {
            var image = $(this);
            var total = $('<div />', {'class' : 'total'});
            var cover = $('<div />', {'class' : 'cover'});
            var crop = $('<div />', {'class': 'crop'});
            var hover = $('<div />', {'class' : 'hover'});
            var peel = $('<div />', {'class' : 'peel'});
            var links = $('<div />', {'class' : 'links'});
            var a = $('<a>', {'href' : '#', 'text' : 'FB'});
            //Chaining begins here
            image.wrap(crop);
            crop.after(hover);

        });
    });

};
})(jQuery);

At first i make variables with divs i will use. But i am having hard time making it all together this time..
I left 2 lines which doesnt want to work with chaining. At first i am wrapping image with crop, and then i am adding hover div after crop div. But… 2nd line doesn’t work. I tried in numerous ways. No luck so far. Seems like it is impossible to add something that is added with “wrap”. Maybe I am doing wrong, so maybe someone of you could help ? 🙂

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:18:48+00:00Added an answer on June 18, 2026 at 12:18 pm

    you can achieve that in this way:

    image.wrap(total).wrap(cover).wrap(crop)
        .closest('.crop')
        .after(a.wrap(hover).wrap(peel).wrap(links).closest('.hover'));
    

    @dystroy’s answer is not totally correct: you can insert thing after a node in memory

    cover.append(crop).append(hover).appendTo('body');
    

    you’ll find all the 3 nodes were appended to DOM

    the key point is $.wrap. when you wrap something, not like other operation, jQuery will create a new copy, at this time, the wrapper in the dom is not the same reference with the one created in memory any more.

    take the first line as example:

    var domCrop = image.wrap(total).wrap(cover).wrap(crop)
        .closest('.crop');
    console.log(domCrop.is(crop)); //false, domCrop and the corp in mem not point to the same ref
    

    the last but not least, in actually, I don’t like this way to extend the dom node. it made the code hard to write and maintain.

    here’s my solution:

    (function($) {
    $.fn.peel = function(options) {
        var defaults = {};
        var settings = $.extend({},defaults, options);
        var html = '<div class="total">'
            + ' <div class="cover">'
            + '   <div class="crop"></div>'
            + '   <div class="hover">'
            + '      <div class="peel">'
            + '         <div class="links">'
            + '            <a href="#">FB</a>'
            + '         </div>'
            + '      </div>'
            + '   </div>'
            + ' </div>'
            + '</div>';
    
        return this.each(function() {
            $(this).load(function() {
                var $image = $(this);
    
                //introduced a placeholder. 
                //not to replace the $image directly, just for keeping all the event handler bound to $image.
                var $placeholder = $('<span/>').insertAfter($image);
                $(html).find('.crop').append($image)
                    .end()
                    .replaceAll($placeholder);
            });
        });
    
    };
    })(jQuery);
    

    jsFiddle Demo: http://jsfiddle.net/vF4QH/1/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to get the class name from a given <tr> tag, but am
I need to extract the top retweets for a given search tag.For that purpose
Given that sorl isn't an app directory wide and the template tag definition lives
Given the following XML I need to place the contents of the suffix tag
I need help doing a few things with XPath in PHP. With any given
I'm given data that could be either a string or an array. I need
Im quite new to doctrine2. I need to make a connection like this: Tag
Given an id of a div tag on my page i need to recursively
I've read that the <marquee> tag is to return in html5... however, I need
I need to retrieve content of <p> tag with given class. Class could be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.