821 posts
  • Power Elite Author: Sold between 1 000 000 - 1 999 999 dollars
  • Power Elite Author
  • Won a Competition
  • Exclusive Author
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Europe
  • Bought between 50 and 99 items
+2 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 been a member for 5-6 years
  • Germany
  • Exclusive Author
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Sold between 5 000 and 10 000 dollars
  • Envato Studio (Microlancer) Beta Tester
  • Bought between 10 and 49 items
  • Referred between 1 and 9 users
BroOf says
2566 posts Put a Donk On It
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • United Kingdom
  • Exclusive Author
  • Attended a Community Meetup
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Referred between 200 and 499 users
+5 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
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 10 and 49 users
  • Serbia
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

821 posts
  • Power Elite Author: Sold between 1 000 000 - 1 999 999 dollars
  • Power Elite Author
  • Won a Competition
  • Exclusive Author
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Europe
  • Bought between 50 and 99 items
+2 more
wpbakery says

Thanks to everyone and especially to Boba.

That did the trick!

1383 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 10 and 49 users
  • Serbia
wpCanyonThemes says

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

You’re welcome :)

4313 posts ThemeForest Reviewer
  • Envato Staff
  • Reviewer
  • Community Moderator
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Venezuela
  • Has been a member for 5-6 years
  • Envato Studio (Microlancer) Beta Tester
  • Sold between 10 000 and 50 000 dollars
  • Exclusive Author
+9 more
Ivor Reviewer says

This is why I effin’ love ThemeForest. :)

by
by
by
by
by
by