1

I'm tryng to run a simple script for an accordion button on Drupal 7.

I had the script tested on a local machine using module "Display suite" allowing me to add custom javascript inside drupal content, and it ran smoothly.

Now I won't be able to use the module on my server so I put the script inside my custom theme, inside the site/all/themes/my_theme/js where a default "script.js" file already loading on all my pages exists, but the script doesn't work any more (the one for my button, the file script.js loads fine).

I'm trying to find a solution using the drupal doc (digging into the drupal_add_js() for now), but as a javascript noob it would greatly help to understand why and how drupal proceeds a script "inside" content differently from external scripts.

Thanks !

1
  • You should read THIS page Commented Jan 20, 2017 at 9:34

2 Answers 2

1

i guess you forgot to include the script inside of your my_theme.info.

this file is located: site/all/themes/my_theme/my_theme.info

you have to include scripts[] = 'js/my_new_script.js'

dont forget to clear your cache.

Sign up to request clarification or add additional context in comments.

1 Comment

Checked it, but the script.js file I use is the default one in my theme, it's included in the my_theme.info file. Thanks for the reminder though !
1

Okay I have found my solution. Drupal is adding a few <p> and <div> elements on some specific HTML elements (<button> in my case) when changing the text format to "Full HTML", thus destroying mercylessly my script.

So to anyone else wondering:

why and how drupal proceeds a script "inside" content differently from external scripts ?

Drupal doesn't proceeds it differently (it does read it after the HTML content if you put it at the far end of content for performance).

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.