Filter the node in real time

The code for filter is in oneditprepare. I tried adding a button that will trigger my function but it still wont trigger until i reopen the node.