I am working on a WordPress plugin and I’ve included jQuery. For some very strange reason the alert
function is not being shown. See code below:
$("#my_button").click(function() {
alert('before hide/show');
$('#divA').hide();
$('#divB').show();
alert('after hide/show');
});
In the code above divA
is actually hidden and divB
is shown, so it means jQuery is working, but strangely enough none of the alert
are being shown.
I am running the code from the plugin options page in the backend.
Why is this happening?
The problem was Firefox Cache. It was the last thing I expected it to be but after doing an Alt F5 it started working.
Not sure, if it’s WordPress issue or just the FF browser but this sorted it for me.
Can’t believe it was the most simple thing :o/ Lesson learned… If the code doesn’t work and it’s not making sense, press ALT F5 First.
Your Code is working fine.
you can see in FIDDLE.
check your other code. May your another function or something else is preventing to show alert?
Or put your code in ONLOAD on form.
Have you called any jQuery file
Try by adding following before your code
The alert function is override by some other code. That ‘s the reason why it doesn’t show the alert box.
You can look at this example then you can understand what I mean
I had same problem. It was not doing a simple alert. The way I solved was just including jQuery.(document).ready after
wp_enqueue_script
like this: