Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-08-2004, 07:06 PM   PM User | #1
iceboxqs
New Coder

 
Join Date: May 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
iceboxqs is an unknown quantity at this point
replace br tag with </div><div>, possible with mozilla?

I find myself here yet again,

Again I am using an editable document in a web page. (document.body)

In IE using outerHTML you can convert a <br> inside a div to </div><div> thus creating two divs that give you the same effect as a <br>.

For example:

I want to change this:

Code:
<div>Here is some content. <br> Here is the second line.</div>
To this:

Code:
<div>Here is some content. </div><div> Here is the second line.</div>
Using mozilla 1.7 if you use the outerHTML the editor changes the "backwards " tag </div><div> to <div></div>, which obviously I do not want.

Heh, I tried making a text node and replacing the <br> but since it's a text node the html code is converted to html character entites.

I'm sure this one will keep me busy for a while. I know I could walk through the current node find all the nodes before the <br> and all the nodes after the <br>, delete the <br>'s parent, create two seprate div's for the content on either side of the <br> and finally insert those two divs.

Pretty ugly though, I was hoping someone would have a much better idea on how this could be done.

Thanks again for your time.
iceboxqs is offline   Reply With Quote
Old 06-11-2004, 09:33 PM   PM User | #2
Choopernickel
Regular Coder

 
Join Date: Apr 2003
Location: Atlanta, GA
Posts: 487
Thanks: 0
Thanked 0 Times in 0 Posts
Choopernickel is an unknown quantity at this point
This is a toughie, and it's a bit dangerous, too: it can yield an invalid document. Consider this starting point:
Code:
<div>
    <p>Here is a line of text<br />
        Here is the second line.</p>
</div>
By replacing the BR with /DIV DIV, you'll end up with this:
Code:
<div>
    <p>Here is a line of text</div>
    <div>Here is the second line.</p>
</div>
There's a lot of parent-element validation involved in this one.

BR isn't going to be deprecated any time soon, since the W3's HTML WG lost its backbone and caved with XHTML 2. It was to be replaced the <l> (L) element, for Line, but they've received a bunch of comments declaring that they're not the same thing, and that usually results in the inclusion of both. At least with the HTMLWG.

Whoa...sorry. Tangent over!
Choopernickel is offline   Reply With Quote
Old 06-18-2004, 12:57 AM   PM User | #3
iceboxqs
New Coder

 
Join Date: May 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
iceboxqs is an unknown quantity at this point
lots of expection checks

Yes, I am aware of many situations like the one you explained. I acutally have it working just fine in IE . . . . lots of expection checking, heh.

I can't use <br> for various reasons I won't expound on.

Anyhow, a simple explanation how I got around around the evil <br>.

Grabing all the child nodes before it and all the child nodes after it. And then inserted the first div before the <br>'s parent and the replaced the <br>'s parent with the second div.

So it comes out like this:

Code:
<div>Here is some content. </div><div> Here is the second line.</div>

Last edited by iceboxqs; 06-18-2004 at 01:00 AM..
iceboxqs is offline   Reply With Quote
Old 06-27-2004, 12:13 AM   PM User | #4
shlagish
Senior Coder

 
Join Date: Apr 2003
Location: Canada
Posts: 1,063
Thanks: 2
Thanked 0 Times in 0 Posts
shlagish is an unknown quantity at this point
Code:
document.body.innerHTML=document.body.innerHTML.replace(new RegExp("<br>","g"),'</div><div>');
Would this not work?
__________________
Shawn
shlagish is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:20 PM.


Advertisement
Log in to turn off these ads.