开发者

Convert function from jQuery("#page>ul>li:last>a").click() to Prototype

开发者 https://www.devze.com 2023-04-05 12:36 出处:网络
I have a statement using jQuery as below: jQuery(\"#page>ul>li:last>a\").cl开发者_StackOverflow社区ick();

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){

 });
0

精彩评论

暂无评论...
验证码 换一张
取 消