- This topic is empty.
-
AuthorPosts
-
July 30, 2023 at 7:42 am #6964
Emily
GuestI have seen this problem sometimes. The dollar sign shorthand doesn’t work and the script will simply not load. I have read to change “$” to be “jQuery” for all instance, is this really necessary? very messy…..
July 30, 2023 at 7:46 am #6965Debra
Guestfor example, in my Child Theme files.
July 30, 2023 at 7:46 am #6966Marie
GuestHere’s a good blog post you might want to check out:
https://dannyda.com/2022/05/22/how-to-use-jquery-where-we-cant-use-the-dollar-sign-does-not-work/
July 30, 2023 at 7:49 am #6967Kyle
Guestgreat cheers mate.
July 30, 2023 at 7:54 am #6968Christopher
GuestYou must use the compatibility mode in WordPress jQuery:
/* Regular jQuery */ $('.hideable').on('click', function() { $(this).hide(); }) /* Compatibility Mode */ jQuery('.hideable').on('click', function() { jQuery(this).hide(); })This article is fantastic and tells you pretty much everything you need to know about how to correctly load jQuery scripts in WordPress. Also remember that WordPress bundles the jQuery library already, so you don’t need to embed that anywhere.
July 30, 2023 at 7:56 am #6969Stephanie
GuestTLDR here’s the common way to save keystrokes:
(function($) { $('.hideable').on('click', function() { $(this).hide(); }) })( jQuery );It tells the script to treat any
$sign asjQuerystring.July 30, 2023 at 8:19 am #6970Anna
Guesta better question is why tf did jQuery bake this into their codebase lol
September 11, 2023 at 7:11 am #8030Andrew
Guest@Stephanie method is most common.
-
AuthorPosts