Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2004
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    innerHTML changes div tag case and removes quotes

    I have a WYSIWYG editor. I am getting the contents of the editor via the Javascript command:

    str = Composition.document.body.innerHTML;

    The problem I'm having is innerHTML converts the case of the DIV tag entered from lowercase to uppercase and strips out the quotes.

    <div class="test">

    becomes:

    <DIV class=test>

    This doesn't affect the display of the HTML, but customers are concerned that their HTML is getting changed. I've tried to use the following to get the DIV tags back to the original case and with quotes:

    myre = new RegExp("DIV class=(.*)>","gi");
    mynewstr = str.replace(myre,"div class=\"$1\"");

    The above does not work. Anytime I try and escape the quotes, it fails. The below fails as well.

    mynewstr = str.replace(myre,'div class=\"$1\"');

    This works, but obviously doesn't have the quotes around the value:

    mynewstr = str.replace(myre,"div class=$1");

    Any help would be appreciated.

    Thanks,

    Robin

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try using the DOM: createElement() rather than the deprecated innerHTML....

    .....Willy

  • #3
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    innerHTML does not change anything... The browser reformats code before parsing because it is much simpler/faster when the order of everything is absolute.

    To undo this, you'll have to re-reformat the code, by enumerating all properties, sorting, changing case, etc., or just use the browser's download behavior to view the source file (if code is not dynamically being altered).
    *this message will self destruct in n-seconds*


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •