0

I have the following code int he post body and it won't run. I can run it from the console just fine, but in the body of the post it won't do anything and doesn't return any kind of error either.

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function($){
    console.log("Test");
    $(".myBox").click(function(){
        var myBoxOn = $(this).attr("data-class");
        $(".myBoxContent").hide("slow");
        $("#" + myBoxOn).show("slow");
    });
});
</script>
0

When you are using Google CDN hosted version of jQuery then you don't need to use jQuery wrapper. It's for jQuery packed with WordPress core because jQuery with WordPress runs in noConflict mode.

So your jQuery code will be.

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript">
  $(document).ready(function() {
    console.log("Test");
    $(".myBox").click(function(){
        var myBoxOn = $(this).attr("data-class");
        $(".myBoxContent").hide("slow");
        $("#" + myBoxOn).show("slow");
    });
  });
</script>
1
  • I know this is almost a year old now but it is probably important to add that adding jQuery in this manner is not the right way. It's better to unset the core jQuery and add your own properly and things work much smoother.
    – o_O
    Nov 5 '15 at 20:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.