We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,379 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

wrapping html paragraphs inside div

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!

3
Contributors
2
Replies
5 Days
Discussion Span
9 Months Ago
Last Updated
3
Views
softDeveloper
Junior Poster in Training
76 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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?

Taywin
Posting Maven
2,633 posts since Apr 2010
Reputation Points: 275
Solved Threads: 375
Skill Endorsements: 17

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

ko ko
Practically a Master Poster
673 posts since Jan 2009
Reputation Points: 120
Solved Threads: 152
Skill Endorsements: 1

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.3096 seconds using 2.66MB