简体   繁体   中英

Mootools element > Object #<HTMLDivElement> has no method 'addEvent'

$$('.img-default > a')[0] 

Delivers me the correct element in the DOM. However, I am not able to add an event.

This code:

$$('.img-default > a')[0].addEvent('click', function(){ //GA code  });

results in:

Object #[HTMLDivElement] has no method 'addEvent'

I followed the docs, which seems pretty straightforward: http://mootools.net/docs/core/Element/Element.Event

EDIT: They seem to have changed Mootools with jQuery overtime. This was possible because Mootools wasn't used extensively and easily replaceable. They, however, apparently never informed us about this.

$('.img-default > a').click(function() {  alert('clicked'); });

this works but links it to al the elements in the array, dont want that

$('.img-default > a')[0]

this returns the href wrapping the big image nicely

$('.img-default > a')[0].click(function() {  alert('clicked'); });

this however, doesnt work >> TypeError: Object [object HTMLAnchorElement] has no method 'click'

Seen this before with jQuery in unsorted lists. Wasnt able to link an index of the

  • elements.

  • try to add add dom ready function :

    window.addEvent('domready',function() {
    // you stuff
    });
    

    The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

     
    粤ICP备18138465号  © 2020-2024 STACKOOM.COM