Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
157
rated 0 times [  158] [ 1]  / answers: 1 / hits: 15796  / 8 Years ago, wed, may 4, 2016, 12:00:00

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?


More From » jquery

 Answers
54

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);

[#62309] Sunday, May 1, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
breonnamayah

Total Points: 574
Total Questions: 115
Total Answers: 96

Location: England
Member since Sun, May 21, 2023
1 Year ago
breonnamayah questions
;