parentNode or previousElementSibling not working in IE8

前端 未结 1 1491
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-17 04:47

I have some javascript, and either parentNode or previviousElementSibling seems to be breaking in IE8. The code works fine in firefox and IE9. This is the line that\'s not

相关标签:
1条回答
  • 2020-12-17 05:08

    previousElementSibling is not supported until IE9.

    http://www.quirksmode.org/dom/w3c_core.html#t84

    Here's a function that should work. Haven't tested it yet. Seems to work.

    var previousElementSibling = function( el ) {
        if( el.previousElementSibling ) {
            return el.previousElementSibling;
        } else {
            while( el = el.previousSibling ) {
                if( el.nodeType === 1 ) return el;
            }
        }
    }
    
    $( previousElementSibling(submitter.parentNode.parentNode) )
    

    EDIT:

    You didn't mention jQuery, but you appear to be using its API. If so, you can just do this:

    $(submitter).closest('form').prev().find('#mark_as_broken').show();
    

    Based on your markup, it appears as though you should be using .find() instead of .children().

    0 讨论(0)
提交回复
热议问题