Reputation: 11
When I located a DOM element via:
$('md-autocomplete-wrap button')[0]
which the browser console actually reveals correctly to be an HTML button, I'd like to click this button through a controller action. Nevertheless:
$('md-autocomplete-wrap button')[0].click();
doesn't do the trick as nothing happens. How do I correctly trigger the click()
function of this button?
Upvotes: 1
Views: 1145
Reputation: 12872
Use jquery trigger
method
$('md-autocomplete-wrap button')[0].trigger('click')
Reference:
http://api.jquery.com/trigger/
Upvotes: 0
Reputation: 4205
Use this code:
http://emberjs.jsbin.com/mimuwale/1/edit
js
App = Ember.Application.create();
function getView($el){
return Ember.View.views[$el.closest(".ember-view").attr("id")];
}
function newAlert(el){
getView($(el)).get('controller').send('newAlert',el.id);
}
App.IndexView=Ember.View.extend();
App.IndexController=Ember.Controller.extend({
actions:{
newAlert:function(buttonId){alert('clicked button:'+buttonId);}
}
});
hbs
<script type="text/x-handlebars" data-template-name="index">
<button id='definition' onclick='newAlert(this)'>test</button>
</script>
Upvotes: 0