Search code examples
cssyui

How to insert a <span> tag after a div in YUI only once?


I am trying to insert a tag after a div via following YUI source:-

      Y.one('#solr_ping_status').insert('<img src="pix/success.png">','after');

The following statement inserts the tag at every click. But I want it to be inserted only once? How can I restrict in to fire an event only once ? or the existing event should override?

Thanks In advance :)


Solution

  • You can use once: http://yuilibrary.com/yui/docs/api/classes/YUI.html#method_once

    example:

    YUI().use('event', function (Y) {
        Y.one('#mybtn').once('click', function (e) {
            alert('clicked');
        });
    });