All geek questions in one place

    Prototype function to set onclick event observer in checkboxes

    I want to set an observer for each of the following flags:

    <div id="listr"> <ul id="lr" style="list-style-type: none"> <p class="tir">Text 1</p> <li class="ro"><input type="checkbox" name="r1" id="r1"/>A1</li> <li class="ro"><input type="checkbox" name="r2" />A2</li> <p class="tir">Text 2</p> <li class="rubro"><input type="checkbox" name="r3" />B1</li> <p class="tir">Text 3</p> <li class="ro"><input type="checkbox" name="r4" />B2</li> </ul> </div> 

    It works if I write one observer per flag, but I want to do it in a short way, so I need something like

     $$('listr.lr.li.input').invoke('observe',click,function(field) { alert(this.name + ' clicked ' + this.checked); // other stuff ... }); 

    What does not work

    Thanks in advance

    +4
    checkbox prototypejs events click
    xain Apr 11 '10 at 15:46
    source share
    1 answer

    Try using a valid CSS3 selector :

     $$('#listr input[type="checkbox"]').invoke('observe','click',function(field) { alert(this.name + ' clicked ' + this.checked); // other stuff ... }); 

    http://prototypejs.org/doc/latest/dom/dollar-dollar/

    +6
    karim79 Apr 11 '10 at 15:50
    source share

    Source: https://habr.com/ru/post/1306613/

    More articles:

    • Is there an equivalent Java ClassFileTransformer in .NET? (a way to replace a class) - reflection
    • What is natural deduction used outside of academia? - logic
    • Game architecture: modeling of various steps / types of user interface - design-patterns
    • Htaccess FCGI handler - django
    • TDD and Encapsulation Priority Conflict - php
    • PHP / HTML / JS / CSS Web Editor - editor
    • Why is this a boolean expression in python False? - python
    • Checking the software availability of a module in Python? - python
    • Should this database table be normalized? - sql
    • Parse HTML with CSS or XPath selectors? - html

    All Articles

    Geek Questions | 2019