Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can attach an event to each first checkbox of divs of class1 by using something like:</p> <pre><code> $('.class1 input:first-child').live('change', function () { </code></pre> <p>(I've used change instead of click because it's a bit more generic. ) Only attaching the first element and not the entire div makes sure you only react when needed.</p> <p>Futher the disabling as you have used it should work, but siblings will only work if your first checkbox is not nested inside another element (e.g. a Paragraph)</p> <p>Example fiddle: <a href="http://jsfiddle.net/Zqz63/" rel="nofollow">http://jsfiddle.net/Zqz63/</a></p> <p><strong>edit</strong> Seeing the html in your updated post , siblings will indeed not work, you could look up in the parents chain to find the .elements div and look down for there for checkboxes (other than the selected)</p> <pre><code> var n = $(this).parents('.elements').find('input:checkbox').not(this); </code></pre> <p>jsfiddle is unresponsive, so I've moved the sample to jsbin: <a href="http://jsbin.com/ahemet/3/edit" rel="nofollow">http://jsbin.com/ahemet/3/edit</a> (NB, in the current jsbin version there is no proper selection of only the first checkbox, so the event will also fire on the 2nd checkbox, but I reckoned that was outside the scope of your question)</p> <p><strong>edit 2</strong> Using the information that class1 is always the first checkbox and class2 always the second:</p> <pre><code>$('input:checkbox.class1').live('change', function () { var n = $(this).parents('.elements').first().find('input:checkbox.class2'); if ($(this).attr('checked')) { n.attr('checked',true); n.attr('disabled', true); } else { n.attr('disabled',false); } }); </code></pre> <p>test: <a href="http://jsbin.com/ahemet/4/edit" rel="nofollow">http://jsbin.com/ahemet/4/edit</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload