Question

I know the click action can be triggered by assigning ontap a specific function like so:

{
kind: "moon.Button",name :"search_button",  
content : "Search" , ontap : "searchAction", classes: "menu-button-style"
}

. . .

searchAction : function(){  //do some stuff on click}

I've tried

$('#id_of_my_button').click();
$('#id_of_my_button').trigger('click');

and none of those seem to work.

simplified jsFiddle

Any ideas

Was it helpful?

Solution

Here, try this:

http://jsfiddle.net/Djspaceg/2AWb5/6/

Enyo has a global handle (enyo) you can use if you need to access any part of its structure. It's not recommended for use from within our app, since it breaks encapsulation, but since you're already outside enyo (by using jQuery or plain JavaScript) I don't see as much harm.

function TapThat() {
    // 'enyo' is the global namespace.
    // The '$' refers to the children of the object/kind.
    enyo.$.tappyButton.tapAction();
}

OTHER TIPS

Why trigger the click with jquery? You can force an event with Enyo, as well:

this.$.someButton.bubble("ontap", {...});

Using the native click function of elements seems to work in your case, like this:

window.onload = function (){
    document.getElementById('tappyButton').click();
};

Demo

Your problem in the fiddle is that you haven't included jQuery. Also, probably that you don't wait for the element to be added to the DOM before binding a click listener to it.

Demo with jQuery

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top