How to Target Immediate Children in a Nested Sortable List?

Susan Sarandon
Release: 2024-11-09 18:12:02
Original
985 people have browsed it

How to Target Immediate Children in a Nested Sortable List?

Targeting Immediate Children in a Nested Sortable List

In a dynamic and n-level deep sortable list, identifying and targeting only immediate children can be challenging. Common child selectors like "ul > li" and "#parent > li" include all child elements, regardless of their nesting level.

To select immediate children exclusively, use the "ul > li" selector. However, this approach is not supported in IE6.

Workarounds for IE6 Compatibility

For backward compatibility with IE6, consider using the following workaround:

#parent li { /* style appropriately */ }
#parent li li { /* back to normal */ }
Copy after login

This method explicitly applies styles to immediate children and then resets them for nested children.

MooTools-Specific Solution

In your MooTools script, the issue arises from using getElements(), which retrieves all descendants. To target only immediate children, use getChildren() instead:

var drop = function(el){
    el.getParents('ul').reverse().each(function(item){
        var posCount = 1;
        item.getChildren("li").getElements("a span[class=position]").each(function(pos){
                pos.set('text', posCount);
                posCount++;
        });
    });
}
Copy after login

The above is the detailed content of How to Target Immediate Children in a Nested Sortable List?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template