Search code examples
windows-store-appswinjs

How can I fire an event in WinJS (equivalent of .trigger("") in jQuery)


I would like to know how can I fire an event from code. In jQuery to fire a "onchange" event you would simply $("selector").trigger("change"). Is there a way to do the same using WinJS.

[All suggestions of including jQuery will be discarded]

Thanks.


Solution

  • fireEvent is probably what you want.

    Fires a specified event on the object.

    Given that markup

    <p>
        <button 
            id="oButton" 
            onclick="this.innerText='I have been clicked!'">Button
        </button>
    </p>
    

    You can do

    oButton.fireEvent("onclick");