简体   繁体   English

如何检查菜单项是否仅在JS Joomla中存在

[英]How to check if menu items exist in Joomla, JS only

I'm a js newbie and I want to check, if a specific menu item exists. 我是JS新手,想检查是否存在特定菜单项。 I'm using Joomla and want to realise this task with js, but not jquery. 我正在使用Joomla,并想用js实现此任务,但不希望使用jquery。 So if this menu item isn't there, I want to change style.width (enlarge) of the other menu items. 因此,如果此菜单项不存在,我想更改其他菜单项的style.width(放大)。 If it's there, I want to reduce the width of all menu items. 如果在那里,我想减小所有菜单项的宽度。 Additionally i want to add an onclick event on this specific menu item. 另外,我想在此特定菜单项上添加onclick事件。 This should generate an art of lightbox popup, article preview or sth. 这应该会产生灯箱弹出,文章预览或其他内容。 with the class "popup" like that. 像这样的“弹出”类 The Css is not the problem, but to display onclick does not work. Css不是问题,但是显示onclick无效。 The popup container i want to show is hidden by default and got it's right position. 我要显示的弹出容器默认情况下是隐藏的,并且位置正确。 In Joomla, i gave my specific menu item the class "offerItem". 在Joomla中,我为我的特定菜单项指定了“ offerItem”类。 First, to switch between display visibility i used this code, but it doesn't worked so far. 首先,在显示可见性之间切换时,我使用了这段代码,但到目前为止还没有奏效。

 document.getElementByClassname("offerItem").addEventListener("click", popup); function popup(){ var z = document.getElementByClassname("popup"); if (z.style.display === "none"){ z.style.display = "block"; } else { z.style.display = "none"; } } 

There's a typo in your code: 您的代码中有错别字:

document.getElementsByClassName('offerItem') // <- Wrong spelling

 document.getElementsByClassName("offerItem").addEventListener("click", popup); function popup(){ var z = document.getElementsByClassName("popup"); if (z.style.display === "none"){ z.style.display = "block"; } else { z.style.display = "none"; } } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM