1
I have a problem with a filter selector, when I choose a city to filter information about it, the browser console shows me the error below. I can’t tell which version of Jquery is being used on the site, I am parachuting into the world of js rs.
In localhost with jquery 2 worked perfectly, after I climbed to the server, started giving this error and stopped working the filter.
Jquery used on the site: https://jsfiddle.net/gLep8kdn/
Full code of custom js https://jsfiddle.net/0kLjj0y5/
Uncaught Typeerror: $ is not a Function at Htmlselectelement.filterlist (custom.js:3)
Code
$('select[name="list_citys"]').change(filterList); 3 ª linha
function filterList(e) {
var value = e.target.value;
$(".list_citys_shop .new-citys").parent().parent().removeClass("hidden");
if (value == "all_city") $(".list_citys_shop .new-citys").slideDown();
else {
$(".list_citys_shop .new-citys").slideUp();
$(".list_citys_shop ul:not([data-category*=" + value + "])").parent().addClass("hidden");
$(".list_citys_shop ul[data-category*=" + value + "]").find(".new-citys").stop().slideDown();
}
}
Probably the jQuery was not loaded.
– Oralista de Sistemas
It is being loaded normally as the other functions of the site work.
– Leonardo
Can you put all the JS code? What’s in the two lines before the line that gives the error?
– Woss
Only comments on what the code performs. After this code comes the bootstrap js https://maxcdn.bootstrapcdn.com/bootstrap.3.7/js/bootstrap.js
– Leonardo
Here the complete code https://jsfiddle.net/0kLjj0y5/
– Leonardo
The code in jsfiddle gives the same error, for the same (probable) reason why it gives error on your site. Check the point at which indicates the path to jQuery.
– Oralista de Sistemas
And where is importing jQuery?
– Woss
No @Andersoncarloswoss jquery is being called in another file before custom js <script src="/Assets/jquery.min.js"></script> <script src=/Assets/custom.js"></script> .
– Leonardo
The code in production http://loja.bluebeach.com.br/preview/testelojas2-126/v Ctrl + u and search by jquery and custom.js
– Leonardo
Leandro mix Angular and jQuery can be one of the reasons, really do not see need to use both, despite different and their way of working, so I looked in the code of the page something is overwriting the global variable
$
.– Guilherme Nascimento
Well, William, the worst thing is that I have no way to edit or remove files, because the site was made on those platforms ready and the guys barely let you touch the js, they analyze all the code before publishing.
– Leonardo
I tried to play the minimum of your code in Jsfiddle (https://jsfiddle.net/ahp9cyn3/) and it seems to be working.
– Woss
@Andersoncarloswoss is a script that overwrites the
$
, maybe the Angular.js– Guilherme Nascimento
@Andersoncarloswosso custom.js is called a 10 lines below the jquery, as you said, it is working normally in jsfiddle, it can be an angular file overwriting the $ even, I will make a test equal the William suggested.
– Leonardo
Guys, I’ll test William’s tip, but I’ll probably only get response from the support (Change the custom js) there by Monday afternoon, then I post the result here. Thank you so much for your help.
– Leonardo