Piumal Chamath
Piumal Chamath

Reputation: 437

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);
        }
    });
}

Upvotes: 0

Views: 301

Answers (2)

Rohan Kumar
Rohan Kumar

Reputation: 40639

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

like,

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

or

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

or

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

Docs parent() closest() parents()

Upvotes: 1

Arun P Johny
Arun P Johny

Reputation: 388316

You can use element.parentNode to get the parent node of element

Upvotes: 1

Related Questions