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

  • Home
  • SEARCH
  • 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 1029825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:36:23+00:00 2026-05-16T12:36:23+00:00

I have a div that I want to write to a popup window (for

  • 0

I have a div that I want to write to a popup window (for printing).

I’m grabbing the contents of the div’s I want on the page using jQuery’s html() function like so:

function printOptions() {
        var printwindow = window.open('', 'Report', 'height=600,width=600');
        printwindow.document.write('<html><head><title>Report</title>');
        printwindow.document.write('</head><body>');
        printwindow.document.write($('#ReportHeader').html());
        printwindow.document.write($('#ReportData').html());
        printwindow.document.write('</body></html>');
        printwindow.document.close();
        printwindow.print();
        return true;
    }

However, before I document.write() the contents of the #ReportHeader and #ReportData div’s, I would like to alter them a little.

Specifically, I would like to replace all textboxes with a simple span containing that textboxes value.

Something like:

$("input[type=text]").each(function() {
    $(this).replaceWith("<span>" + $(this).val() + "</span>"); 
});

How can I do that to just the contents of those divs without altering my existing page? I just want to modify what I’m going to be writing out to the print window. I don’t think I can select on what the html() returns though, because it is just returning a string.

I do ~not~ want to modify the original page that is launching the popup. Just the contents of what I’m going to be writing to the popup.

Any ideas on how I could do this?

  • 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-05-16T12:36:24+00:00Added an answer on May 16, 2026 at 12:36 pm

    You can use .clone() to do it efficiently, like this:

    printwindow.document.write(
      $('#ReportHeader').clone().find("input[type=text").each(function() {
        $(this).replaceWith("<span>" + $(this).val() + "</span>"); 
      }).end().html()
    );
    

    This gets a copy of the original #ReportHeader and its children so you can manipulate them how you want without modifying the original, as well as not enduring the expense of html string -> node conversion, which is compartively quite expensive.

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

Sidebar

Related Questions

I have the following function that I only want to run inside <div id=imgWrapper>
I have a JavaScript function that returns a string. I want to write this
I have a DIV that I want to touch the bottom of the screen
I have a div that I want to toggle between displaying or not when
I have a div that I want when user click on a button slideUp
I have a div set transparent with rgba and want on that div an
I have 5 images that I am appending to a div that I want
I have a floating div that gets displayed, and I want it to be
I have old text inside a div. I want that text to fly out
I have an id: div id =untitled-region-5 I want to grab that id and

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.