Jquery toggle not working

≡放荡痞女 提交于 2019-11-29 10:18:43

You need to:

  1. Use document.ready
  2. Select the anchor underneath the #one div, not the div itself

So it should be:

$(document).ready(function() {
  $("#one a").click(function() {
    $("#hideme").toggle();
  });
});
Lewis

Your not wrapping your javascript in $(document).ready(function(){}) etc do jQuery is trying to find an element that doesn't exist yet!

I am having the same situation while using ajax and applied this solution. Write javascript:void(0); instead of a '#' in href value. this prevents you to add '#' in url. use .live() when using in ajax mode. in .toggle(), pass argument as effect like 'Drop', 'slide' etc, more at http://jqueryui.com/toggle/.

$(document).ready(function(){
        $('#one a').live('click', function(){
            $('#hideme').toggle('Drop');
            return false;
         });
     });

Applying return false; at last preventing me to reload the page.

Answered just for knowledge.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!