828 posts
    Power Elite Author: Sold more than $1M on Envato Market Won a competition Made it to the Authors' Hall of Fame Has sold $1M+ on Envato Market and is now a Power Elite Author
+7 more
wpbakery says

Hey,

How can I select “text” in the following code and wrap it in a “span” tag?

<div class="wrap">
   This text should be selected and wrapped in a span
   <span class="span_class_name">Another content</span>
</div>

Thanks guys!

1799 posts
    Has referred 1+ members Has sold $5,000+ on Envato Market Has been a beta tester for an Envato feature Has collected 10+ items on Envato Market
+4 more
BroOf says
2566 posts Put a Donk On It
    Has referred 200+ members Has sold $250,000+ on Envato Market Has collected 10+ items on Envato Market Elite Author: Sold more than $75,000 on Envato Market
+10 more
ThemeProvince says

Use the .text() function.


var textsample = $(' div.wrap ').text();

textsample = "<span>" + textsample + "</span>";

// Clear contents of wrap div then add the text again.

$(' div.wrap ').html("").append(textsample);

I think this will work.

1383 posts
    Has been part of the Envato Community for over 4 years Has referred 10+ members Has collected 10+ items on Envato Market Sells items exclusively on Envato Market
+1 more
wpCanyonThemes says

I think he’s not gonna have that exact sentence every time :)

@mixey – This was a tough one, thank you for this little challenge :) Here you go:

$('.wrap').each(function(){

    $(this.childNodes).filter(function(index) {
        if(this.nodeType === 3 && this.nodeValue != ''){ return true; }
    }).wrap('<span>');

});
</span>
Edit: Stupid forum eating my code :) Gimme a sec.

Here you go http://pastie.org/1579886

828 posts
    Power Elite Author: Sold more than $1M on Envato Market Won a competition Made it to the Authors' Hall of Fame Has sold $1M+ on Envato Market and is now a Power Elite Author
+7 more
wpbakery says

Thanks to everyone and especially to Boba.

That did the trick!

1383 posts
    Has been part of the Envato Community for over 4 years Has referred 10+ members Has collected 10+ items on Envato Market Sells items exclusively on Envato Market
+1 more
wpCanyonThemes says

Thanks to everyone and especially to Boba. That did the trick!

You’re welcome :)

4323 posts ThemeForest Reviewer
    Has referred 1+ members Has sold $40,000+ on Envato Market Has collected 50+ items on Envato Market Member of the Envato Team
+12 more
Ivor Envato team says

This is why I effin’ love ThemeForest. :)

by
by
by
by
by
by