是否有替代.toggle()的jquery [英] is there an alternative to .toggle() for jquery

查看:63
本文介绍了是否有替代.toggle()的jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前根据Jquery 网站 .toggle()已被折旧1.8版之后。那么有什么替代.toggle(),因为我需要菜单应用程序的功能,我需要隐藏和显示基于按钮点击的div的内容

Currently as per Jquery site .toggle() has been depreciated after 1.8 version. So is there any alternative to .toggle() as i need the function for menu app in which I need to hide and show contents of a div based on button click

我已经根据 JSFiddle 完成了任务,但我已经加载了1.12.4版本的jquery在我的网站上用于其他用途

I have already accomplished the task according to JSFiddle but I am already loading 1.12.4 version of jquery on my site for other usage

我的Js功能代码

function hideToggle(button, elem) {

  $(button).toggle(
    function() {
      $(elem).hide();
    },
    function() {
      $(elem).show();
    }  );
}

hideToggle(".button1", ".iframe1");

那么有没有办法阻止加载两个版本的jquery

So is there a way to prevent loading two versions of jquery

推荐答案

这基本上是隐藏 show 是做。

CSS

.hidden {
 display:none;
 /* you could also use !important here */
}

JQuery

  $('#someElement').toggleClass('hidden');

这篇关于是否有替代.toggle()的jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆