Christopher Punton
Christopher Punton

Reputation: 139

How do you add $(document).ready(function() to joomla

I need to add this to joomla I've tried adding it to the template index.php file but it doesn't work any ideas?

<script type="text/javascript">
 $(document).ready(function() {
   $("nav#menu").mmenu(
    {
      classes: "mm-light"
   });
});
</script>

Upvotes: 0

Views: 2720

Answers (1)

Lodder
Lodder

Reputation: 19733

You're Joomla site is importing jQueury in noConflict mode, therefore you must either use the jQuery alias, or pass the $ through the function, like so:

$doc = JFactory::getDocument();
$doc->addScriptDeclaration('
    jQuery(document).ready(function($) {
       $("nav#menu").mmenu({
           classes: "mm-light"
       });
    });
');

The above code is PHP so you can place it anywhere in your template within PHP tags.

I've also noticed on your site that the responsive menu is now working. Tested in Chrome and Firefox.

Upvotes: 4

Related Questions