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.