如何添加此javascript代码以便按下按钮? [英] How do I add this javascript code to work on button click?
本文介绍了如何添加此javascript代码以便按下按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,我有这段代码:
Hello, i have this code:
<script> document.addEventListener("DOMContentLoaded", function(event) { jQuery('.elementor-tab-title').removeClass('elementor-active'); jQuery('.elementor-tabs').css('display', 'none'); }); </script>
一旦页面加载就会隐藏css元素。
当我点击按钮时,如何显示/隐藏
which hides a css element as soon as the page loads.
how can i show/hide
.elementor-tabs
?
我尝试了什么:
我已经尝试了所有我能想到的,但因为它不是一个div我不确定。有什么想法吗?
when i click a button?
What I have tried:
I've tried all i can think off, but as its not a div im not sure. Any ideas?
推荐答案
用HTML创建你的按钮:
Create your button in HTML:
<button id="elementorTabsButton">Button text</button>
和你的JavaScript:
And your JavaScript:
jQuery("#elementorTabsButton").click(function() {
jQuery(".elementor-tab-title").toggleClass("elementor-active");
jQuery(".elementor-tabs").toggle();
});
toggleClass添加或删除一个类,具体取决于它是否存在。
toggle显示或隐藏元素。
边节点:你可以写
"toggleClass" adds or removes a class, depending on if it's there or not.
"toggle" shows or hides an element.
Side node: you can write
作为 jQuery的简写
。
这篇关于如何添加此javascript代码以便按下按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文