Is it possible to make so that when a certain function is activated, all the elements in the class work? I.e:

<div class="one"> <div onclick="func_one();">Кролик_1</div> <div onclick="func_two();">Кролик_2</div> </div> 

It is necessary that all functions in this class work. Thanks in advance!

  • one
    > all the elements in the class worked;>> all the functions in this class worked. The cruel question ... Hey, frequents - did the extrasensory leave leave come back? - Palmervan
  • Nikita090, are you interested in a solution without JQuery or can you use it? - Nicolas Chabanovsky
  • one
    I went to correct the mistake of youth I retrain to a psychic and I will be banging loot on other resources, who is with me? - Artem

1 answer 1

A little govnokoda - and voila!

 <div class="one"> <div onclick="alert(this.innerHTML);">Кролик_1</div> <div onclick="alert('2');">Кролик_2</div> </div> <script> function dunno(cname, type){ var all = document.getElementsByTagName('*'); var classEls = []; for(var i = 0, il = all.length; i < il; ++i){ if(all[i].className.indexOf(cname)+1){ classEls[classEls.length] = all[i]; } } for(var i = 0, il = classEls.length; i < il; ++i){ all = classEls[i].getElementsByTagName('*'); for(var j = 0, jl = all.length; j < jl; ++j){ var todo = all[j].getAttribute('on'+type); if(todo){ var f = new Function(todo); f.apply(all[j]); } } } } dunno('one', 'click'); </script> 

Yes, for the future: a class in javascript is not what you mean. Google
And not everyone can understand what “triggered elements” means either. Think how to explain in professional or more obvious terms.