0

I'm having trouble accessing my div elements with jQuery after implementing snap.js in my Ratchet project, does anyone know why and how can I fix this?

document.getElementById('mydivId').innerHTML   //THIS WORKS
$('#mydivId').html()  //THIS DOESN'T WORK

I've included the jquery.js and implemented $(document).ready(function(){});

I get "Uncaught TypeError: Cannot call method 'ready' of null"

Ry-
  • 218,210
  • 55
  • 464
  • 476
Jasper Giscombe
  • 313
  • 1
  • 5

2 Answers2

0

OK, I found what the issue is... turns out Snap.js also uses the $ alias like Jquery, so that's what creates the conflict. In the script tag on the index.html i renamed all occurrences of $ and changed it to $$.

    // Helper
    $$ = function(id){
        return document.getElementById(id);
    }, 
                ....
                $$('right-drawer').classList.add('active-drawer');
                ....
                $$('toggle-left').addEventListener('click', function(){
                    snapper.open('left');
                 });

and so forth.

Jasper Giscombe
  • 313
  • 1
  • 5
0

try something like this,instead of $ use jQuery,so renaming anything.

 jQuery( document ).ready(function( $ ) {
   // Code that uses jQuery's $ can follow here.
 });

Other alternative

var j = jQuery.noConflict();
// Do something with jQuery
j( "div p" ).hide();
rajesh kakawat
  • 10,826
  • 1
  • 21
  • 40