this is what an html structure of the webpage looks like:
<body>
<form>
<input type='file'/>
</form>
<div id='list'>
<div>value here<input id='delete' type='button'/></div>
</div>
</body>
i have found javascript code that triggers on ‘delete’ button click and removes input ‘file’ element. it uses this piece of code where element is input ‘file’ mentioned above:
deleteButton.onclick=function(){this.parentNode.element.parentNode.removeChild(
this.parentNode.element );}
i am trying to understand logic(rules) behind ‘this.parentNode.element’ ? why not accessing element directly ‘element.parentNode.remove…’
many thanks
There’s no
elementproperty on theNode,Element,HTMLElement, orHTMLDivElementinterfaces. So my guess would be that elsewhere in that code, you’ll find something that’s explicitly adding that property to the element instance of thedivcontaining the button. You can do that, add arbitrary properties to element instances. These are frequently called “expando” properties and should be done very, very, very carefully.