# Conflicting jQuery Issue

**URL:** <https://community.hubspot.com/t/conflicting-jquery-issue/12006>\
**Category:** APIs & Integrations\
**Created:** [February 15, 2018, 5:24pm UTC](https://community.hubspot.com/t/conflicting-jquery-issue/12006 "2018-02-15T17:24:03Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/system/32/124_2.png) [@system](https://community.hubspot.com/u/system)\
**Post date:** [February 15, 2018, 5:24pm UTC](https://community.hubspot.com/t/conflicting-jquery-issue/12006/1 "2018-02-15T17:24:03Z")

</div>

I’m trying to run 2 jQuery scripts on 1 page and am not sure how to do it. I have both scripts running in a HubL code module in a global footer. One is for the Mobile Menu, the other is for an accordion. I put the accordion module on this page: [http://www-apexhomeloans-com.sandbox.hs-sites.com/lopage](http://www-apexhomeloans-com.sandbox.hs-sites.com/lopage)

jQuery code in the HubL template is below. Both scripts run individually, but the accordion script doesn’t run if the mobile menu script is there.

---

<div class="post-metadata">

**Author:** ![system](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/system/32/124_2.png) [@system](https://community.hubspot.com/u/system)\
**Post date:** [February 15, 2018, 8:03pm UTC](https://community.hubspot.com/t/conflicting-jquery-issue/12006/2 "2018-02-15T20:03:05Z")

</div>

Looks like the error is Uncaught TypeError: $ is not a function  
at lopage:893 at the accordion element. Try wrapping the jquery in a self invoking function and moving everything into one script tag.

```auto
$(function() { 
 })();

```

---

<div class="post-metadata">

**Author:** ![system](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/system/32/124_2.png) [@system](https://community.hubspot.com/u/system)\
**Post date:** [February 15, 2018, 9:21pm UTC](https://community.hubspot.com/t/conflicting-jquery-issue/12006/3 "2018-02-15T21:21:52Z")

</div>

[@fly.space.age](https://community.hubspot.com/u/fly.space.age)

Thanks. I meant to include the actual code, but I think I left html tags around it so it didn’t show up lol. It is exactly what you’re saying, but I’m not sure how to fix it. I’m just using code that I found online for each section and don’t really know jQuery, unfortunately.

MOBILE MENU CODE

var $mobile = jQuery.noConflict();  
$mobile(function() {

```auto
/** 
 * Mobile Nav
 *
 * Hubspot Standard Toggle Menu
 */
$mobile('.custom-menu-primary').addClass('js-enabled');
$mobile('.custom-menu-primary .hs-menu-flow-horizontal').before('<a class="mobile-trigger"><span></span><i></i></a>');
$mobile('.custom-menu-primary .flyouts .hs-item-has-children > a').after('<a class="child-trigger"><span></span></a>');
$mobile('a.mobile-trigger').click(function() {
 $mobile(this).next('.custom-menu-primary .hs-menu-flow-horizontal').slideToggle(250);
 $mobile('body').toggleClass('mobile-open');
 $mobile('a.child-trigger').removeClass('child-open');
 $mobile('.hs-menu-children-wrapper').slideUp(250);
 return false;
 });

$mobile('a.child-trigger').click(function() {
 $mobile(this).parent().siblings('.hs-item-has-children').find('a.child-trigger').removeClass('child-open');
 $mobile(this).parent().siblings('.hs-item-has-children').find('.hs-menu-children-wrapper').slideUp(250);
 $mobile(this).next('.hs-menu-children-wrapper').slideToggle(250);
 $mobile(this).next('.hs-menu-children-wrapper').children('.hs-item-has-children').find('.hs-menu-children-wrapper').slideUp(250);
 $mobile(this).next('.hs-menu-children-wrapper').children('.hs-item-has-children').find('a.child-trigger').removeClass('child-open');
 $mobile(this).toggleClass('child-open');
 return false;
});

```

});

ACCORDION CODE

var $accordion = $(’.accordion’);

// Initially hide all accordion content  
$accordion.find(’.accordion\_content’).hide();  
// Initially display the accordion content with .expanded class  
$accordion.find(’.accordion\_group.expanded .accordion\_content’).show();

$accordion.find(’.accordion\_header’).click(function(){

```auto
// Hide the displayed sibling accordion content so only one appears at a time

```

$accordion.find(“.accordion\_header”).not(this).parent(“.accordion\_group.expanded”).removeClass(‘expanded’).children(’.accordion\_content’).stop(true,true).slideUp();

```auto
if(!$(this).parent('.accordion_group').hasClass('expanded')){
 // Display the accordion content if it is not displayed
 $(this).parent(".accordion_group").addClass('expanded').children('.accordion_content').stop(true,true).slideDown();
}
else{
 // Hide the accordion content if it is displayed
 $(this).parent(".accordion_group").removeClass('expanded').children('.accordion_content').stop(true,true).slideUp();
}

```

});

---

<div class="post-metadata">

**Author:** ![system](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/system/32/124_2.png) [@system](https://community.hubspot.com/u/system)\
**Post date:** [February 15, 2018, 9:27pm UTC](https://community.hubspot.com/t/conflicting-jquery-issue/12006/4 "2018-02-15T21:27:30Z")

</div>

```auto
$(document).ready(function(){

var $mobile = jQuery.noConflict();
$mobile(function() {
 /** 
 * Mobile Nav
 *
 * Hubspot Standard Toggle Menu
 */
 $mobile('.custom-menu-primary').addClass('js-enabled');
 $mobile('.custom-menu-primary .hs-menu-flow-horizontal').before('<a class="mobile-trigger"><span></span><i></i></a>');
 $mobile('.custom-menu-primary .flyouts .hs-item-has-children > a').after('<a class="child-trigger"><span></span></a>');
 $mobile('a.mobile-trigger').click(function() {
 $mobile(this).next('.custom-menu-primary .hs-menu-flow-horizontal').slideToggle(250);
 $mobile('body').toggleClass('mobile-open');
 $mobile('a.child-trigger').removeClass('child-open');
 $mobile('.hs-menu-children-wrapper').slideUp(250);
 return false;
 });

 $mobile('a.child-trigger').click(function() {
 $mobile(this).parent().siblings('.hs-item-has-children').find('a.child-trigger').removeClass('child-open');
 $mobile(this).parent().siblings('.hs-item-has-children').find('.hs-menu-children-wrapper').slideUp(250);
 $mobile(this).next('.hs-menu-children-wrapper').slideToggle(250);
 $mobile(this).next('.hs-menu-children-wrapper').children('.hs-item-has-children').find('.hs-menu-children-wrapper').slideUp(250);
 $mobile(this).next('.hs-menu-children-wrapper').children('.hs-item-has-children').find('a.child-trigger').removeClass('child-open');
 $mobile(this).toggleClass('child-open');
 return false;
 });
});

/** 
 * jQuery Accordion
 *
 * 
 */
var $accordion = $('.accordion');

// Initially hide all accordion content
$accordion.find('.accordion_content').hide();
// Initially display the accordion content with .expanded class
$accordion.find('.accordion_group.expanded .accordion_content').show();

$accordion.find('.accordion_header').click(function(){

 // Hide the displayed sibling accordion content so only one appears at a time
 $accordion.find(".accordion_header").not(this).parent(".accordion_group.expanded").removeClass('expanded').children('.accordion_content').stop(true,true).slideUp();

 if(!$(this).parent('.accordion_group').hasClass('expanded')){
 // Display the accordion content if it is not displayed
 $(this).parent(".accordion_group").addClass('expanded').children('.accordion_content').stop(true,true).slideDown();
 }
 else{
 // Hide the accordion content if it is displayed
 $(this).parent(".accordion_group")
.removeClass('expanded').children('.accordion_content').stop(true,true).slideUp();
 }
});

})(jQuery);

```

---

<div class="post-metadata">

**Author:** ![system](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/system/32/124_2.png) [@system](https://community.hubspot.com/u/system)\
**Post date:** [February 15, 2018, 9:59pm UTC](https://community.hubspot.com/t/conflicting-jquery-issue/12006/5 "2018-02-15T21:59:40Z")

</div>

[@fly.space.age](https://community.hubspot.com/u/fly.space.age) Hmm. Should that work as is? Seems both aren’t working if I put it in that way. Thanks for your help! I at least know the issue, just have to figure out how to combine the two functions into 1 script now.

[http://www-apexhomeloans-com.sandbox.hs-sites.com/lopage](http://www-apexhomeloans-com.sandbox.hs-sites.com/lopage)

---

<div class="post-metadata">

**Author:** ![system](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/system/32/124_2.png) [@system](https://community.hubspot.com/u/system)\
**Post date:** [February 15, 2018, 10:04pm UTC](https://community.hubspot.com/t/conflicting-jquery-issue/12006/6 "2018-02-15T22:04:04Z")

</div>

Try adding the self-invoking function around the document.ready. I think the problem is that the browser doesn’t know to look for the jQuery library.

```auto
(function ($) {
 $(document).ready(function() {

 });
 })(jQuery);

```

[stackoverflow.com](https://stackoverflow.com/questions/33056230/uncaught-typeerror-ready-is-not-a-function) [  
  ![]()  
 ](https://stackoverflow.com/users/5419041/nick-m)

#### 

[Uncaught TypeError: $(…).ready is not a function](https://stackoverflow.com/questions/33056230/uncaught-typeerror-ready-is-not-a-function)

**jquery**

[  
Nick M  
 ](https://stackoverflow.com/users/5419041/nick-m) on [04:29PM - 10 Oct 15](https://stackoverflow.com/questions/33056230/uncaught-typeerror-ready-is-not-a-function)

---

<div class="post-metadata">

**Author:** ![system](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/system/32/124_2.png) [@system](https://community.hubspot.com/u/system)\
**Post date:** [February 16, 2018, 12:53am UTC](https://community.hubspot.com/t/conflicting-jquery-issue/12006/7 "2018-02-16T00:53:42Z")

</div>

Thanks, bud! Works now. I just ended up switching every “$” to “jQuery” like they said in that SO post. Definitely have to start learning javascript and jQuery - I’m more on the marketing end and do PPC campaigns and stuff like that, but I do want to learn more development. Thanks again!
