I am using the pdf_reader module and showing my PDF on the node. Now, I am supposed to hide the download button. For this purpose, I wrote the below javascript file:

jQuery(document).ready(function($) {
  document.querySelector('#download').style.display = 'none';

It's also in my theme's libraries.yml file. The last thing I did was write a hook_preprocess_node implementation and put in the below code:

  $node = \Drupal::routeMatch()->getParameter('node');
  if ($node->getType() == 'e_dergi') {
    $variables['#attached']['library'][] = 'conference_lite/custom';

But I can't hide the download button for the life of me. What else should I try?

1 Answer 1


If your theme name is fluffiness in "fluffiness.info.yml" add following lines

  - fluffiness/global-scripts

in your file "fluffiness.libraries.yml" add following lines

  version: 1.x
  js/fluffiness.js: {} 

  - core/jquery
  - core/drupal

in your file "js/fluffiness.js" add following code

(function (Drupal, drupalSettings, once) {
   Drupal.behaviors.hideElement = {
     attach: function (context, settings) {
 } (Drupal, drupalSettings, once));
  • Nope, didn't work :(
    – Kartagis
    Feb 14, 2022 at 10:50
  • Please check 1) file added on page using "View Page Source" 2) check any js error in browser
    – khurrami
    Feb 14, 2022 at 10:56
  • Page source doesn't include it, however an additional console.log says it's loaded.
    – Kartagis
    Feb 14, 2022 at 12:03
  • i think you should go through in detail, the way of adding js as mentioned here drupal.org/docs/theming-drupal/… look at this regarding cuddly-slider.js as they have explained in detail this might help you.
    – khurrami
    Feb 14, 2022 at 12:37
  • @Kartagis Any JS errors in browser's console? Why not do it via CSS #download { display: none; }
    – No Sssweat
    Feb 16, 2022 at 12:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.