Good afternoon to evening. Using prototype.js I encountered a problem: I’m <a class='someclass'> up all <a class='someclass'> elements

 var x = $$('.someclass'); for (var i=0; i<x.length; i++) { Event.observe(x[i], 'click', this.popup.bindAsEventListener(this)); } 

But, by clicking it, it follows the link specified in the href property. But he should not. You cannot use other properties for the link located in the href property. Solved the problem by onCLick="return false;" property onCLick="return false;" . I want a more concise solution. I understand you need to use Event.stop(); ? But how? Thank you in advance.

    1 answer 1

    It stops like this:

      for (var i=0; i<x.length; i++) { Event.observe(x[i], 'click', function(e){ // some code there ... Event.stop(e); }); } 

    I understand that this.popup.bindAsEventListener (this) returns the function, if so, then just rewrite the code like this:

      var eventHandler = this.popup.bindAsEventListener(this); for (var i=0; i<x.length; i++) { Event.observe(x[i], 'click', function(e){ eventHandler(); Event.stop(e); }); } 

    In general, the question is elementary, next time, first see here - Prototype JS API , and Google has not been canceled

    • Thank you, apparently looking bad :) - stck
    • Apparently =) - Zowie