admin管理员组文章数量:1026406
I've got a mobile menu that will toggle on, but it just won't go away.
my JS:
const menu = document.getElementById("mobile-menu");
const button = document.getElementById("navButton");
button.addEventListener("click", function(){
if (menu.style.display="none") {
menu.style.display="block"
} else {
menu.style.display="none"
}
})
and my PHP in header.php:
wp_nav_menu(array(
'theme_location' => 'header-menu',
'menu_id' => 'mobile-menu',
What am I missing to make this toggle off?
Thanks in advance
I've got a mobile menu that will toggle on, but it just won't go away.
my JS:
const menu = document.getElementById("mobile-menu");
const button = document.getElementById("navButton");
button.addEventListener("click", function(){
if (menu.style.display="none") {
menu.style.display="block"
} else {
menu.style.display="none"
}
})
and my PHP in header.php:
wp_nav_menu(array(
'theme_location' => 'header-menu',
'menu_id' => 'mobile-menu',
What am I missing to make this toggle off?
Thanks in advance
Share Improve this question asked Mar 29, 2019 at 9:59 JakePowellJakePowell 431 silver badge10 bronze badges 2- This is no WordPress-specific question and must be considered off-topic. – norman.lol Commented Mar 29, 2019 at 18:58
- I believe that it is something to do with how WordPress generates menus or how JS integrates with templates, because it's a fairly simple JS script that isn't doing what it should. Even JS lifted directly from a tutorial like W3 schools will not work in this case. I've still not cracked it! – JakePowell Commented Apr 1, 2019 at 11:56
1 Answer
Reset to default 0Please read this documentation https://developer.wordpress/reference/functions/wp_nav_menu/
menu_id
(string) The ID that is applied to the ul element which forms the menu. The default is the menu slug, incremented.
container_id
(string) The ID that is applied to the container.
Try to add container_id
in wp_nav_menu
array(), I hope it'll help you out. Thanks
wp_nav_menu(array(
'theme_location' => 'header-menu',
'menu_id' => 'mobile-menu',
'container_id' => 'mobile-menu',
)
)
I've got a mobile menu that will toggle on, but it just won't go away.
my JS:
const menu = document.getElementById("mobile-menu");
const button = document.getElementById("navButton");
button.addEventListener("click", function(){
if (menu.style.display="none") {
menu.style.display="block"
} else {
menu.style.display="none"
}
})
and my PHP in header.php:
wp_nav_menu(array(
'theme_location' => 'header-menu',
'menu_id' => 'mobile-menu',
What am I missing to make this toggle off?
Thanks in advance
I've got a mobile menu that will toggle on, but it just won't go away.
my JS:
const menu = document.getElementById("mobile-menu");
const button = document.getElementById("navButton");
button.addEventListener("click", function(){
if (menu.style.display="none") {
menu.style.display="block"
} else {
menu.style.display="none"
}
})
and my PHP in header.php:
wp_nav_menu(array(
'theme_location' => 'header-menu',
'menu_id' => 'mobile-menu',
What am I missing to make this toggle off?
Thanks in advance
Share Improve this question asked Mar 29, 2019 at 9:59 JakePowellJakePowell 431 silver badge10 bronze badges 2- This is no WordPress-specific question and must be considered off-topic. – norman.lol Commented Mar 29, 2019 at 18:58
- I believe that it is something to do with how WordPress generates menus or how JS integrates with templates, because it's a fairly simple JS script that isn't doing what it should. Even JS lifted directly from a tutorial like W3 schools will not work in this case. I've still not cracked it! – JakePowell Commented Apr 1, 2019 at 11:56
1 Answer
Reset to default 0Please read this documentation https://developer.wordpress/reference/functions/wp_nav_menu/
menu_id
(string) The ID that is applied to the ul element which forms the menu. The default is the menu slug, incremented.
container_id
(string) The ID that is applied to the container.
Try to add container_id
in wp_nav_menu
array(), I hope it'll help you out. Thanks
wp_nav_menu(array(
'theme_location' => 'header-menu',
'menu_id' => 'mobile-menu',
'container_id' => 'mobile-menu',
)
)
本文标签: javascriptMobile menu will only toggle on
版权声明:本文标题:javascript - Mobile menu will only toggle on 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745647049a2161086.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论