简体   繁体   中英

how to get the parent node of a child node

I'm having issues with identifying the parent of one of my child nodes . code is as follows

if (!queryCommandState('InsertUnorderedList') 
    && !queryCommandState('InsertOrderedList')) {
    // If forced_root_blocks is set to false we don't have a block to indent so lets create a div
    if (!settings.forced_root_block 
        && !dom.getParent(selection.getNode(), dom.isBlock)) {
        formatter.apply('div');
    }

    each(selection.getSelectedBlocks(), function(element) {
        var indentStyleName;

        if (element.nodeName != "LI") {
            indentStyleName = dom.getStyle(element, 'direction', true) == 'rtl' ? 'paddingRight' : 'paddingLeft';

            if (command == 'outdent') {
                value = Math.max(0, parseInt(element.style[indentStyleName] || 0, 10) - intentValue);
                dom.setStyle(element, indentStyleName, value ? value + indentUnit : '');
            } else {
                value = (parseInt(element.style[indentStyleName] || 0, 10) + intentValue) + indentUnit;
                dom.setStyle(element, indentStyleName, value);
            }
        }
        if (element.nodeName=== "OL"){
            alert ("got");
        } else {
            alert (element.nodeName);
        }
    });
}
  • want to find the parent of the "element.nodeName"*

您可以使用element.parentNode来获取element的父节点

You can use jquery.parent() or jquery.closest()

like,

$(element).parent('selecter');

or

$(element).closest('selecter');

or

$(element).parents('selecter');

Docs parent() closest() parents()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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