Vishnu Murale
Vishnu Murale

Reputation: 173

Parse not working in jQuery

I'm trying to make a website that uses parse. My java script will be shown below. The js is linked and I've made sure to include

   <script src="//www.parsecdn.com/js/parse-1.6.12.min.js"></script> 

in the html. My js :

$(document).ready(function() {

  Parse.initialize("assumeisright", "assumeisright");

  var TestObject = Parse.Object.extend("TestObject");
  var testObject = new TestObject();
  testObject.save({
    foo: "bar"
  }).then(function(object) {
    alert("yay! it worked cash muni");
  });

  $("div").hover(
    function() {
      $(this).addClass("active");
    },
    function() {
      $(this).removeClass("active");
    }
  );

  Parse.Push.send({
    channels: ["Everyone"],
    data: {
      alert: "First Push"
    }
  }, {
    success: function() {
      // Push was successful
    },
    error: function(error) {
      // Handle error
    }
  });

});

This doesn't work because in my html my div doesn't change when I hover so I'm assuming the Parse crashed. Any ideas of how to fix this, am I doing something wrong?

Thanks

Upvotes: 0

Views: 217

Answers (1)

Raunak Kathuria
Raunak Kathuria

Reputation: 3225

As you are using jquery so you need to import that library as well, so final code will be something like this

<!doctype html>
<html>
<head>
    <style>
    </style>
    <script src="http://www.parsecdn.com/js/parse-1.6.12.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script>
        $(document).ready(function() {
            Parse.initialize("assumeisright", "assumeisright");

            var TestObject = Parse.Object.extend("TestObject");
            var testObject = new TestObject();
            testObject.save({
                foo: "bar"
            }).then(function(object) {
                alert("yay! it worked cash muni");
            });

            $("div").hover(
                function() {
                    console.log('add');
                    $(this).addClass("active");
                },
                function() {
                    $(this).removeClass("active");
                }
            );

            Parse.Push.send({
                channels: ["Everyone"],
                data: {
                    alert: "First Push"
                }
            }, {
                success: function() {
                    // Push was successful
                },
                error: function(error) {
                    // Handle error
                }
            });
        });
    </script>
</head>

<body>
    <div>
        <p>Hello</p>
    </div>
</body>

</html>

On hover i have added console.log('add') just to test if hover is working fine, it outputs add when you hover over div

   $("div").hover(
    function() {
        console.log('add');
        $(this).addClass("active");
    },

Always check your browser console for errors

Upvotes: 2

Related Questions