Convert function from jQuery("#page>ul>li:last>a").click() to Prototype
I have a statement using jQuery as below:
jQuery("#page>ul>li:last>a").cl开发者_StackOverflow社区ick();
How can I do that in Prototype?
The selector is the same in prototype as it is in jQuery. The difference is you have to use the $$
function in prototype and then iterate over each selected element :
$$("#page > ul > li:last > a").each(function(element) {
eventFire(element, "click");
});
Looks like prototype does not have a method like jQuery's trigger
. You can write a function like the one found in this answer:
function eventFire(el, etype){
if (el.fireEvent) {
(el.fireEvent('on' + etype));
} else {
var evObj = document.createEvent('Events');
evObj.initEvent(etype, true, false);
el.dispatchEvent(evObj);
}
}
$$('#page>ul>li:last>a')[0].on('click',function(event){
});
精彩评论