0

I'm working on a project that makes use of a print stylesheet. I need to manipulate the DOM when a user prints the page to change the layout. (unfortunately cannot be done via aforementioned stylesheet).

After some research, I figured it would be acceptable to have jquery check if the navigation was hidden, (we have it set to display: none; when print styles are active) then include the DOM manipulation needed (the font-size: 100px was just a visual check to see if it works):

if ($('#topnav').is(':hidden')) {
  const headTwo = $('section div.tab-wrapper ul.nav.nav-tabs li a');
  headTwo.css('font-size', '100px');
}

However, when run it returns "undefined." I threw an else in there to test if the

const headTwo = $('section div.tab-wrapper ul.nav.nav-tabs li a');
headTwo.css('font-size', '100px');

was the problem, but it works as intended. Is there any reason that the print style for #topnav cannot be used in the statement?

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
wilt
  • 3
  • 1
  • Which part, exactly, is returning undefined? – Taplar Jul 23 '18 at 16:38
  • @Taplar I'm not sure what you mean, this is what I see when in the console: https://imgur.com/a/ADjySfw – wilt Jul 23 '18 at 16:42
  • You are seeing that because the if statement does not have a return. It's just one of the things your browser console does. It tries to echo the return of any statement it runs. If there isn't a return, it's undefined. – Taplar Jul 23 '18 at 16:43
  • Ah, would I then need to write a function with the code above to have the statement return? – wilt Jul 23 '18 at 16:46
  • No, this isn't a problem. Your script isn't going to be running in your browser console for normal users, :) – Taplar Jul 23 '18 at 16:46
  • Gotcha, thanks for all the help @Taplar! – wilt Jul 23 '18 at 16:53

0 Answers0