This still won't move the optional caption text (see my post above).
On Jun 6, 4:21 pm, Charlie <charlie...@gmail.com> wrote: > One reason I follow this board is to learn how to do things I haven't > encountered. I had no idea off top of my head how to do what you want but in > quest to learn jQuery many of the problems on this board are great for > training one's self. Thanks to team jQuery for such a good library and for > excellent API docs and examples > solution is very straight forward and easy to test with the markup of <p> > some text <img /></p> > //test example > $("img").each(function() { > if ($(this).parent().is("p")){ > alert("My Parent is a P"); > $(this).insertBefore($(this).parent()); > } > }); > in your case you should be able to put following right after your > .each(function (i) {: > if ($(this).parent().is("p")){ > $(this).insertBefore($(this).parent()); > } > ///rest of your function > var a = $(this).attr('alt');............ > Bruce MacKay wrote:Hi folks, > The following function takes an image tag (or table) that appears within a p > tag container in the form< p> <img> text < /p>and wraps the image (and > caption if a title is present) into a div for floating left, right, or > centering. > My problem is that I don't know how to shift the processed image from within > the p container to immediately before it (so that the created div is not > within a p container) > I'd appreciate help in this next step. > Thanks, > Brucefunction fnDoImages() { > > $('img.imgposl,img.imgposr,img.imgposc,img.tblposl,img.tblposr,img.tblposc').each(function(i) > { > var a = $(this).attr('alt'); > var q = $(this).attr('class').substr(0,3); > var p = $(this).attr('class').substr(6); > var t = $(this).attr('title'); > var w = $(this).attr('width'); > if (a.length=0) { > $(this).attr('alt',''+t+''); > } > $(this).wrap("<div class='buggybox clearfix' > id='g"+i+"'></div>"); > if (q=='tbl' && t.length>0) { > $(this).before("<p class='imgcaption' > style='width:"+w+"px;'>"+t+"</p>"); > } else if (t.length>0){ > //$(this).after("<p class='imgcaption' > style='width:"+w+"px;'>"+t+"</p>"); > }; > $("#g"+i).addClass("img"+p).css({width:w+'px'}); > }); > }