Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8463907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:34:50+00:00 2026-06-10T14:34:50+00:00

<!DOCTYPE html> <html><body> <p id=intro>Hello <em id=abcd>intro</em> World!</p> <script type=text/javascript> var txt=document.getElementById(intro).innerHTML; var el

  • 0
<!DOCTYPE html>
<html><body>

<p id="intro">Hello <em id="abcd">intro</em> World!</p>

<script type="text/javascript">
var txt=document.getElementById("intro").innerHTML;
var el = document.createElement("span");
el.innerHTML = txt;
var aa = el.getElementById("abcd").innerHTML;
alert( aa );
</script>
</body></html>

The above is a simple snippet. Actually I have an HTML editor and when the user saves the data I should save only the required content. Here I am getting the content of an element and manipulating it with DOM and pass the details to the server. This way I will not change the page content (user view remains the same) and he/she will continue editing the document.

The above is a simple example but in the real case I have to remove, change and move certain elements. The above code fails el.getElementById("abcd").innerHTML. Appreciate any pointers.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T14:34:52+00:00Added an answer on June 10, 2026 at 2:34 pm

    You can create a hidden iframe to manipulate all your changes, thus creating a separate DOM, then simply pull back the results you want.

    var iframe;
    if (document.createElement && (iframe = document.createElement('iframe'))) {
        iframe.name = iframe.id = "externalDocument";
        iframe.className = "hidden";
        document.body.appendChild(iframe);
    
        var externalDocument;
        if (iframe.contentDocument) {
            externalDocument = iframe.contentDocument;
        } else if (iframe.contentWindow) {
            externalDocument = iframe.contentWindow.document;
        }
        else if (window.frames[iframe.name]) {
            externalDocument = window.frames[iframe.name].document;
        }
    
        if (externalDocument) {
            externalDocument.open();
            externalDocument.write('<html><body><\/body><\/html>');
            externalDocument.close();
    
            /* Run your manipulations here */
            var txt = document.getElementById("intro").innerHTML;
            var el = document.createElement("span");
            el.innerHTML = txt;
    
            /* Attach your objects to the externalDocument */
            externalDocument.body.appendChild(el);
    
            /* Reference the externalDocument to manipulate */
            var aa = externalDocument.getElementById("abcd").innerHTML;
            alert(aa);
        }
    
        /* Completed manipulation - Remove iFrame */
        document.removeChild(iframe);
    }
    

    I have it working here:
    http://jsfiddle.net/ucpvP/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

See example: <!DOCTYPE html> <html> <head> <title>language</title> <script type=text/javascript src=http://www.google.com/jsapi> </script> </head> <body> <div
<!DOCTYPE HTML> <html> <head> <script type=text/javascript src=http://code.jquery.com/jquery-1.7.2.js></script> <script type=text/javascript> $(#myBtn).on(click,function(){ alert('myBtn Clicked'); }); </script>
HTML <!doctype html> <html> <head> </head> <body> <button id=b1 type=button>Show Spoiler</button> <p id=p1 style=display:none>
<!DOCTYPE HTML> <html> <body> <video width=320 height=240 controls=controls> <source src=tutorial.mp4 type=video/mp4 /> Your browser
i am trying to understand following fragment of javascript code <!DOCTYPE html> <html> <body>
<!DOCTYPE html> <html> <head> <meta http-equiv=Content-Type content=text/html; charset=utf-8/> <title>FAQ Section</title> <link rel=stylesheet type=text/css href=styles.css/>
Imagine a fairly simple HTML document <!DOCTYPE HTML > <html> <body> <table> <tr> <td>
Consider a document in the following format: <!DOCTYPE html> <html> <head> <title></title> <body> <div
<!DOCTYPE html> <html> <head> <meta name=viewport content=initial-scale=1.0, user-scalable=no /> <meta http-equiv=content-type content=text/html; charset=UTF-8 />
I have the following html and css code: <!DOCTYPE HTML> <html> <head> </head> <body>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.