Script to fire an event as soon as an element exists?

◇◆丶佛笑我妖孽 提交于 2019-12-01 14:14:03
Brock Adams

This is a common problem. You can act on AJAXed-in elements as they appear by using the waitForKeyElements() utility. (See "Fire Greasemonkey script on AJAX request" for example.)

I'm not sure what you mean by "the little box which appears when hitting a post's arrow-icon", but in general, you would:

  1. Make sure your script has jQuery. Add this to the metadata section, if it's not there already:

    // @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
    


  2. Require-in waitForKeyElements:

    // @require https://gist.github.com/raw/2625891/waitForKeyElements.js
    


  3. Write your handler function and activate it:

    function hideTheNews (jNode) {
        //***** YOUR CODE HERE *****
        jNode.hide (); // For example
    }
    
    waitForKeyElements ("*APPROPRIATE jQuery SELECTOR*", hideTheNews);
    
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!