1

I have an issue with a jquery script using text node to find and wrap text in a div.

It's ignoring <b> elements at the very start. But not after any plain text.

<b>Bold introduction</b>
content content content <b>content</b> content

To this:

<b>Bold introduction</b>

<div class="description">
content content content <b>content</b> content

</div>

One solution I can think of is to remove <b> elments and then reinsert them after the text node script has fired. Is the possible? Thanks

EDIT: sorry wasn't clear. The above is what I want to fix. Ie:

<div class="description">
<b>Bold introduction</b>
content content content <b>content</b> content

</div>

Here is the text node script jsfiddle with the error js fiddle

uriah
  • 2,485
  • 5
  • 28
  • 40

1 Answers1

0

To turn this:

<b>Bold introduction</b>
content content content <b>content</b> content

into this:

<b>Bold introduction</b>

<div class="description">
content content content <b>content</b> content

</div>

I think you want

$("b:first").nextAll().wrapAll("<div class='description' />");

EDIT

If you want to move these elements into the description div, then this should do that

var toMove = $("b:first").nextAll().remove();
$(".description").append(toMove);
Adam Rackis
  • 82,527
  • 56
  • 270
  • 393
  • Could I `.append` that to the div? – uriah Dec 16 '11 at 03:51
  • @uriah - probably - I'm not sure what you mean. The code above takes everything after the first , and wraps them in a div of class'description' -- is that not what you want? – Adam Rackis Dec 16 '11 at 03:56
  • nah, I wanted to move it into the `.description` after the `.description` has been made. Sorry – uriah Dec 16 '11 at 04:27