Score:0

I can't load inline jQuery

in flag

I have a Drupal 9 page, where I am trying to load some inline jQuery code, from CKEditor, but it isn't working and I am not getting any error on the console.

This worked perfectly in Drupal 8.

<script>
 window.onload = function() {
  jQuery('.className').fadeOut();
  console.log("HI");
 };
</script>
Kevin avatar
in flag
These things are generally not done, nor advised, from WYSIWYGs.
KVF-IT avatar
in flag
From a frontend developer view (I do backend as well,) I think that it involves too many steps, to create modules or libraries, just to swap a couple of divs around and add some css. It is very convenient to just go into the CKEditor and splash out some jQuery, that is only meant to do its work, on a specific page or block.
Score:0
in flag

The right way of doing it, is to add a js file to the js folder, then declare it in the my-theme.libraries.yml file, either globally or not. Then the trick is to make a hook for the specific node (or node-type, even theme) in the my-theme.theme file.

leymannx avatar
ne flag
Yeah and never put it in a contrib theme. Either create a new custom sub-theme or a custom module from where you attach the JS like it's written in the docs.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.