简体   繁体   English

如何使用JQuery检索无序列表的li标签并将这些标签放入数组中?

[英]How can I retrieve the li tag of an unordered list and put these tags into an array using JQuery?

I am pretty new in JQuery and I have the following problem. 我在JQuery中还很陌生,但遇到以下问题。

Into a page I have the following unordered list : 进入页面,我有以下无序列表

<ul id="menu-language" class="nav">
    <li id="menu-item-422" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-422">
        <a href="http://localhost/onyx/prova/">prova cat</a>
    </li>

    <li id="menu-item-185" class="qtranxs-lang-menu qtranxs-lang-menu-it menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children menu-item-185">
        ..............................
        SOMETHING
        ..............................
    </li>
</ul>

I need to create a JQuery script that retrieve all the li tag (and the related HTML content of these tags) and that put it into something like an array (so each position of this array have to contain a li tag and its HTML content). 我需要创建一个JQuery脚本,该脚本检索所有li标签(以及这些标签的相关HTML内容)并将其放入类似数组的内容中(因此该数组的每个位置都必须包含li标签及其HTML内容) 。

What is the smarter way to do it using JQuery? 使用JQuery的更聪明的方法是什么?

Tnx 特纳克斯

$('#menu-language > li') will return an array of li nodes, you can get the content of each li element by iterating: $('#menu-language > li')将返回一个li节点数组,您可以通过迭代获得每个li元素的内容:

$('#menu-language > li').each(function() {
console.log($(this).html());
});

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

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