Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Peter Buckwalter
6,846 Pointsjs opening and closing tags on scripts break functions.
Hello,
I am working on moving some scripts out of my divi theme integrations section and enquing them in the child them functions.php.
I have setup a number of script.js files in my-theme/js/ folder and I have coppied the code into the files, but I finding that the code is rejected while the opening and closing tags are in place.
I am not even close to an expert in js, but if there is any advise on what might be going on here I would happy to hear it.
Cheers,
Peter
3 Answers
Rich Donnellan
Treehouse Moderator 27,741 Points<script> tags are only required when you're directly embedding into an HTML file (inline or externally). When all of your code resides in a .js file, no <script> tags are required.
The enqueueing functionality in WordPress will add an external <script src="path/to/file"> to the HTML. It will definitely error out the way you have it.
Peter Buckwalter
6,846 PointsThank you.
Can you see any obviouse errors in the code?
I am noticing when the code is enqued in functions.php not all of the code functions correctly, but the same code in the divi includes section works perfectly.
Best,
Peter
Rich Donnellan
Treehouse Moderator 27,741 PointsImpossible for me to eyeball any errors. I have the faintest what you're trying to accomplish.
Peter Buckwalter
6,846 PointsThis is everything from the integrations section.
<script>
jQuery(document).ready(function(){jQuery('.et-cart-info').clone().insertAfter('.mobile_menu_bar_toggle');});
</script>
<script>
(function($) {
function setup_collapsible_submenus() {
var $menu = $('#mobile_menu'),
top_level_link = '#mobile_menu .menu-item-has-children > a';
$menu.find('a').each(function() {
$(this).off('click');
if ($(this).is(top_level_link)) {
$(this).attr('href', '#');
}
if (!$(this).siblings('.sub-menu').length) {
$(this).on('click', function(event) {
$(this).parents('.mobile_nav').trigger('click');
});
} else {
$(this).on('click', function(event) {
event.preventDefault();
$(this).parent().toggleClass('visible');
});
}
});
}
$(window).load(function() {
setTimeout(function() {
setup_collapsible_submenus();
}, 700);
});
})(jQuery);
</script>
<script>
(function($) {
$(document).ready(function() {
$('.et-cart-info').attr('href', '#0');
});
})(jQuery);
</script>
I have broken it down into three separate scripts, but it only seems to work in the integrations section of divi
Peter Buckwalter
6,846 PointsThanks Rich
Rich Donnellan
Treehouse Moderator 27,741 PointsNo problem. Good luck!
Rich Donnellan
Treehouse Moderator 27,741 PointsRich Donnellan
Treehouse Moderator 27,741 PointsCan you post some code? It's pretty difficult to visualize what you're trying to accomplish.