I created custom WordPress page via plugin where I want to toggle on/off comments using this code
<script type="text/javascript">
$("comment_switch").click(function () {
$("comments").toggleClass("hidden");
});
</script>
I placed it inside the <body>
tag. To generate <head>
tag I used standard WordPress function wp_head();
. When I check the source code of the page I can see in head section <script src="http://10.1.1.6/wp-includes/js/jquery/jquery.js?ver=1.10.2" type="text/javascript">
which I thought would be enough to use jQuery.
Could someone help me to make the jQuery code work? The whole source code of the page could be found here
You're probably missing some .
class markup and the DOM ready function
jQuery(function($) { // DOM is now ready and jQuery's $ alias sandboxed
$(".comment_switch").on("click", function () {
$(".comments").toggleClass("hidden");
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With