jQuery is included in the file, like this:
wp_enqueue_script("jquery");
And I have a jQuery file that looks like this:
$(function() {
alert("j");
$('.event-wrapper a').click(function(){
event.preventDefault();
if($(this).next().is(':visible')) {
$(this).next().hide();
} else {
$('.event-info').hide();
$(this).next().show();
}
});
$('.event-info').click(function() {
$(this).hide();
});
});
This is not working. I have tried putting only the alert(“j”); in the file, and that works so the file is correctly included. How can I fix this?
WordPress automatically calls jQuery with jQuery.noConflict which means that $ is removed to avoid namespace collisions. When using jQuery with WordPress you should always use jQuery instead of $.
For example:
In order to get $ back you can use the shortcut described here (and in other answers): http://docs.jquery.com/Using_jQuery_with_Other_Libraries