I am only able to create an alert box in jQuery but Javascript works perfectly.
-
I am trying to change an image source using jQuery. Now, when I try to use jQuery, I have only gotten an alert box to work. I can do everything perfectly in javascript, but jQuery just does not want to cooperate. jQuery is listed as a dependency and the fact that I can create an alert box means everything is registered and enqueued properly.
I was just testing to see if I could make an alert when I click on a certain element, but no luck. Can anyone tell me what the error is in this code?
This works:
(function($){ alert("hello"); }(jQuery));
Next I tried to create an alert when I click an element with an Id selector. This does NOT work:
(function($){ $('#slide-holder').on('click', function(){ alert("hello"); }); }(jQuery));
Then I tried with a class selector. This also does NOT work:
(function($){ $('.picture-place-holder').on('click', function(){ alert("hello"); }); }(jQuery));
I checked and double checked to make sure my id and class match the element I want to add the event to, but WordPress seems to really not want me to use jQuery. I also do not have any plugins installed that use jQuery. Can anyone see the problem in my code??
- The topic ‘I am only able to create an alert box in jQuery but Javascript works perfectly.’ is closed to new replies.