Reputation: 49404
I am having this error when I click on the following code:
onclick="tester.removeit(this);"
I get Error:
TypeError: $(...).parent is not a function
Here is the function:
removeit: function(ele) {
$(ele).parent('div').fadeOut();
console.log(this);
},
How can I fix this?
Upvotes: 3
Views: 16888
Reputation: 1074919
Sounds like a library conflict, where you're including PrototypeJS or MooTools after including jQuery.
When you do that, only one library can use $
as its main identifier. You can tell jQuery to "release" $
via noConflict
:
<script src="jquery.js"></script>
<script>jQuery.noConflict();</script>
<script src="prototypejs.js"></script>
Then in code where you want to use jQuery, use jQuery
rather than $
:
// ...
removeit: function(ele) {
jQuery(ele).parent('div').fadeOut();
console.log(this);
},
// ...
Or wrap all of your code using jQuery in an IIFE that accepts $
as an arg:
(function($) {
// ...
removeit: function(ele) {
$(ele).parent('div').fadeOut();
console.log(this);
},
// ...
})(jQuery);
Upvotes: 3