1

I want to use click function in Wordpress single.php

for that, I have used below code

<div class="wrapper clearfix">
  <a href="#" id="mobile-menu-toggle" class="lines-button">
    <span class="lines"></span>
   </a>
</div>

$(document).ready(function(){
  $('.clearfix a').click(function(){
    alert();

  });
});

and when I use this code I have received the error Uncaught TypeError: $(...).MagicLiquidizerTable is not a function

I have searched for this error and I have got this and this code.

and as this question, I have tried

jQuerydocument).ready(function($){
  $('.clearfix a').click(function(){
    alert();

  });
});

and with

$.noConflict();

jQuery(function ($) {
  console.log($); 
});

console.log($);

I have tried that both but it is still not working and got again this error Uncaught TypeError: $(...).MagicLiquidizerTable is not a function.

can anybody help me with this

2 Answers2

0

Not sure how you have set up the html but if the class clearfix is a div surrounding the href then it should work.

If you are putting the class clearfix in the href like <a href="#" class='clearfix'>TEST</a> then it will not work or use a class name like clearfix1 and test if it works or not.

EDIT: I have used your code above an this causes no errors. There must be something on the rest of your page that is conflicting with this that we can not see in your code. It is probably a class name. I would change the class name and test to see if it is a class name conflict first.

$(document).ready(function(){
  $('.clearfix a').click(function(){
    alert("this works");

  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>


<div class="wrapper clearfix">
  <a href="#" id="mobile-menu-toggle" class="lines-button">
    <span class="lines">test</span>
   </a>
</div>
Icewine
  • 1,851
  • 1
  • 12
  • 22
0

WordPress comes with its own jQuery version, You can enqueue it using below function. It will be added by its own if you mentioned jquery as dependency while enqueue another JS file.

wp_enqueue_script("jquery");

Many plugins used in wordpress use jQuery instead of $ to be on safe end. If you want to use $ instead of jQuery please add below code at top of jQuery file or script.

var $ = jQuery.noConflict();

You can also use $ inside your read statement as well as shown below.

    jQuery(document).ready(function ($) {
        //Your JS Code
     });
Rahat Hameed
  • 412
  • 3
  • 16