Class is still visible after the media query preview is looked at, despite attempts

Our print preview library is set up to display the final product to users, but we don't want the images to actually be printed since we are using branded paper.

To address this, I have included a print media query in the print.css file and added all images to the hideImg class defined within that file.

I am trying to figure out why the print media query is not functioning as expected or how I can adjust the library or jQuery code. I have attempted different approaches such as placing the images in different divs and modifying the displayed content on the preview screen, but without success.

Although the classes are correctly applied, no errors are shown in the console.

CSS :

@media print {
/* -- Hide screen specific elements -- */
.hideImg{

    display:none !important;
    visibility:hidden !important;

        }
}

jQuery

var images = document.getElementsByTagName("img");
            var i;

                for(i = 0; i < images.length; i++) {
                    images[i].className += "hideImg";
                }

HTML

<div id="content" class="container_12 clearfix">

     <div id="printableArea" style="display:none;">
        <img src="images/badgeHead.png" alt"needs more jpg"/>
                                      <h1>Hi, my name is...<br/> 
                                      </h1>

                                      <br>
         <img src="images/badgeFoot.png" alt"needs more jpg"/>
                                </div>    
</div>

Library jQuery

// Bind closure
            $('a', print_controls).bind('click', function(e) {
                e.preventDefault();
                //adding the printframe contentwindow rather than body prints out just what we want
                if ($(this).hasClass('print')) { print_frame[0].contentWindow.print(); }
                else { $.printPreview.distroyPrintPreview(); }
            });

Answer №1

For the best results, try running the following code snippet in full screen mode and print it out to see the text that will be displayed.

@media print {
  /* -- Hide screen specific elements -- */
  .hideImg {
    display: none !important;
    visibility: hidden !important;
  }
}
<div id="content" class="container_12 clearfix">

  <div id="printableArea" style="display:none;">
    <img src="images/badgeHead.png" alt "needs more jpg"/>
    <h1>Hi, my name is...<br/> 
                                      </h1>

    <br>
    <img src="images/badgeFoot.png" alt "needs more jpg"/>
  </div>
  <div class="hideImg">hello</div>
  <h3>check</h3>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Display stylish Instagram-like dots in the slick slider

Currently, I am utilizing the slick slider to display numerous slider items. Additionally, I want to include dots to indicate the position of the items. However, there are too many dots visible at once, and I wish to display them similarly to how Instagram ...

Modifying Blocks in Prestashop: A Step-by-Step Guide

I'm looking to make some changes to the "categories" block in my left navigation column. Currently, it appears like this: https://i.sstatic.net/MpUD5.png I would like it to look like this by default: https://i.sstatic.net/fJTr8.png Here are the mod ...

Is there a way to retrieve JSON data from a different domain and incorporate it into my own website?

I am attempting to utilize JSON data from "" and display the data on my website. My goal is to extract the JSON field name "Stats" and retrieve the sub-field name '\"v\"'. You can refer to the documentation provided by purpleair here: h ...

Understanding the functionality of an array as an index in JavaScript

It was discovered (tested in Chrome) that the index of an array can actually be an array itself: a = [1, 2, 3] index = [1] a[index] // returns 2 Has there been any official documentation confirming this behavior? ...

Error while retrieving reference from mongoDB in NodeJS

I am currently working on a small website that needs to query my local mongodb. Everything works perfectly fine on localhost. That's why I decided to begin with NodeJS. While all JavaScript functions work seamlessly when run separately, I encounter a ...

Unable to establish a connection with the node at http://localhost:8545

Issues Encountered: I am having trouble with the Web3.min.js path in my system directory! The Web3.min.js file is being loaded from a folder in my browser. I have copied the web3.min.js file to the same folder where the index.html file is l ...

Tips for transferring the AJAX result data to a jQuery datatable

I am looking to transfer the response data from an AJAX page to a jQuery Datatable function. Can you please provide guidance on the correct syntax for passing the result into the Datatable function? function getResultsMsr(action, msrDel) { if( ...

Ways to apply CSS styling to a specific SVG element without affecting others?

Originally, I had created a single bar chart using SVG: bars.append("rect") .attr("x", midX) .attr("y", 0) .attr("width", function(d) { return x(d.values[0].value); }) .attr("height", y.bandwidth()) .classed("highlight", function(d) { retu ...

Ignoring the partial view's click action

Within my parent view, there is a partial view containing two pseudo buttons: thumb up and thumb down, along with a paragraph containing assigned classes. Despite setting up two functions to execute when 'ready', the partial view does not respon ...

Text wrapping to the right of an image in Bootstrap columns

I'm struggling with getting a large block of text to display correctly on the right side of an image. The text keeps dropping below the image when it reaches a certain size or if no width is specified. Adding a fixed width to the text column seems to ...

Concerns with the Width of Gutters in Susy

I am working with a 24 Susy column grid and trying to create boxes that span 6 columns each, allowing for 4 boxes per row. However, I also want to add gutters around them within a wider container that is 24 columns wide. Despite my efforts, the columns do ...

Creating custom functionality using Node.js and MySQL

I recently started working with NodeJS and I'm in the process of creating an API service. The GET function is working fine, but I'm encountering issues with the POST function: router.post("/venditori",function(req,res){ var query = "INSE ...

Retrieving the ID of a div element using jQuery from a string

Greetings! I have encountered an interesting challenge while working within a jQuery foreach loop. Within this loop, I am retrieving a div element in the form of a string. The string contains a div with an id specified as <div id="div1"> Some text& ...

Performing an asynchronous request within a dynamic helper (or a suitable substitute) in Express version 2.x

I'm attempting to display the total message count for a user's inbox on my website's layout. I initially thought of utilizing Express' dynamicHelpers to achieve this, but in versions of Express <= 2.x, these helpers do not support as ...

Display text in SVG format with a unique styling that splits the content into two distinct lines

Below is an SVH text element: View the JSFiddle here - http://jsfiddle.net/E4VvX/ <text y="9" x="0" dy=".71em" style="text-anchor: middle; max-width: 30px;width: 30px;white-space: pre-wrap;" >Jul 2014</text> The text currently appears in a s ...

Is it feasible to utilize Sublime Editor for building SCSS/SASS files? Learn how to compile SCSS/SASS with Sublime Editor

Despite numerous attempts, I have been unable to figure out how to effectively use the Sublime Editor for creating scss/sass files. ...

Troubleshooting Wordpress: Using PHP and Curl to post data and avoid page refresh, encountering issues with Curl functionality

Currently, I am working on developing a donation page that allows the submission of credit card information without the need to refresh the page. I have managed to successfully implement an overlay using jQuery. With the help of a PHP if statement, I am ab ...

Loading an image on select using JQuery DatePicker

New to the world of asp.net Mvc and jquery. I have this code snippet that is functioning well, but I need to dynamically load the image src each time the onSelect event of the datepicker is triggered. Any assistance would be greatly appreciated. <scri ...

Sveltejs template not displaying on M1 MacBook Air after running - stuck on blank screen

Currently, I am in the process of learning Sveltejs and have been utilizing for the tutorial, which has been quite effective. However, I decided to work on developing and testing Sveltejs applications locally on my MacBook Air M1. I downloaded the provid ...

Can someone please explain how to apply various fonts to the text in a `<p>` paragraph using CSS and HTML?

Take a look at this image Can you provide guidance on how to incorporate various fonts within a paragraph, like the example shown in the image above? I am experimenting with the "Creative Corner" section. ...