Hi!

I am trying to wrap some html paragraphs inside a div element:

<p>1st paragraph</p>
<p>2nd paragraph</p>
<p>3rd paragraph</p>


I want to have this when I select this text from an iframe with window.getSelection():

<div>
<p>1st paragraph</p>
<p>2nd paragraph</p>
<p>3rd paragraph</p>
</div>

and, in case I select 2 paragraphs and a half, the div woud end before </p>:

<div>
<p>1st paragraph</p>
<p>2nd paragraph</p>
<p>3rd parag</div>raph</p>

Thanks in Advance!

Recommended Answers

All 2 Replies

Could we see your script? Not sure how you did it. By the way, when you do the selection, did you attempt to check the DOM for parent/neighbor nodes instead of only the text selection?

In jQuery, you can use $('p').wrap('div'). Anyway, post more details to get more implementation.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.