问题描述
我有 3 列 UL,每个动态 UL 容器可以有 0-9 个 LI 容器(最终更多).我所有的 LI 元素都有一个属性rel",我试图最终找到该属性并将其用于该父 DIV 中所有 LI 元素的其他内容.我最终确实想找到更多基于每个但不是最起码的 rel.. 任何想法我可以如何使用 jQuery 实现这一目标?示例:
I have 3 Columns of ULs each a Dynamic UL container that can have anywhere from 0-9 LI containers (eventually more). All my LI elements have an attribute "rel" which I am trying to ultimately find that attribute and use it for something else on all LI elements within that parent DIV. I do eventually want to find more based on each but for not the very least the rel.. Any Ideas how I can achieve that with jQuery? Example:
<ul id="column1">
<li rel="1">Info</li>
<li rel="2">Info</li>
<li rel="3">Info</li>
</ul>
<ul id="column2">
<li rel="4">Info</li>
<li rel="5">Info</li>
<li rel="6">Info</li>
</ul>
<ul id="column3">
<li rel="7">Info</li>
<li rel="8">Info</li>
<li rel="9">Info</li>
</ul>
这些元素也是可排序的.因此,当我获得它们的列表时,我还想按照它们从每列的顶部到底部找到它们的顺序来保持它们.
these elements are all sortable as well. So when I get a list of them I want to also keep them in the order they were found from top to bottom of each column.
我已经尝试过 find()、parent() 和类似的方法,也许我处理错了.但它仍然值得一提,以帮助提出一个想法
I have tried find(), parent(), and similar, maybe I am approaching it wrong. But its still worth mentioning to help come up with an idea
推荐答案
你在想这样的事情吗?
$('ul li').each(function(i)
{
$(this).attr('rel'); // This is your rel value
});
这篇关于jQuery 查找并列出特定 DIV 中 UL 内的所有 LI 元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!