I think you could use this too. $('img').filter(function(){return !$(this).parent('p').length == 1}).wrap('<p></p>');
On Thu, May 7, 2009 at 9:51 PM, Charlie Griefer <charlie.grie...@gmail.com> wrote: > > On Thu, May 7, 2009 at 8:45 PM, Charlie Griefer > <charlie.grie...@gmail.com> wrote: >> On Thu, May 7, 2009 at 8:08 PM, dduck1934 <dduck1...@gmail.com> wrote: >>> >>> im trying to get the syntax down to find all img tags that are NOT >>> surrounded by <p> tags and wrap those img tags in <p> tags. >>> >>> I can get the selector to get all img tags and wrap it in a <p> tag >>> but i need to further take it to disregard the img tags that already >>> are wrapped in <p> >> >> with my usual disclaimer that the following code might suck: >> >> $('img').each(function(){ >> if ($(this).parent().get(0).tagName != "p") { >> $(this).wrap(document.createElement('p')); >> } >> }); > > hmm... not sure if the 'tagName' value can always be assumed to be > lowercase (or uppercase). > > changing line 2 to: > > if ($(this).parent().get(0).tagName.toLowerCase() != "p") { > > -- > I have failed as much as I have succeeded. But I love my life. I love > my wife. And I wish you my kind of success. >