[英]JQuery Selector Issue: How to select anything is a child of the current list item
I'm sure that title is confusing. 我确定标题令人困惑。 This is a Wordpress thing. 这是一个WordPress的东西。
So, I have a list of pages and the structure looks like this: 因此,我有一个页面列表,其结构如下所示:
<div id="menu">
<ul> <!--List of pages-->
<li class="page-item page-id">
<a href="Page url"> Ham Man </a>
<ul class="children">
<li class="page-item page-id">
<a href="Page url"> Page 1</a></li>
<li class="page-item page-id">
<a href="Page url"> Page 2</a></li>
</ul>
</li>
</ul>
</div>
My problem is this- There are MULTIPLE titles like 'Ham Man'. 我的问题是-有“ Ham Man”之类的多个标题。 So what I need to is work a bit of jQuery so when someone clicks on a title, it displays the PAGES for that title. 因此,我需要做的是使用jQuery,以便当有人单击标题时,它会显示该标题的PAGES。 Easy enough. 很简单。 But when I have multiple titles, this gets tricky. 但是当我有多个标题时,这会很棘手。
WHat I need to say is "WHEN someone clicks on a li element in the menu column, display all of the CHILD ELEMENTS (class 'children') JUST for that LI element". 我需要说的是:“当有人单击菜单列中的li元素时,仅显示该LI元素的所有儿童元素(类'children')。
It's gotta be simple, but I can't work it. 它必须很简单,但是我无法使用。
A solid Plan B is just to have Wordpress drop a class of 'Parent' into the 'Parent' elements, but that seems like a recipe for MURDER. 可靠的计划B只是让Wordpress将“父”类放到“父”元素中,但这似乎是谋杀的秘诀。
Thoughts? 有什么想法吗? Thanks ahead of time! 提前谢谢!
should be: 应该:
$('#menu > ul > li').bind('click', function(){
var elems = $(this).find('.children').children();
// elemens contains all child nodes from ul.children
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.