Good all the time of day, gentlemen.

  1. We have a table inside the table in one of the checkbox cells. When you click on a line, you want to activate / deactivate it (just like in phpmyadmin). In the internet there are a couple of solutions on this topic, but unfortunately there you need to add a class that I have busy. Are there any alternative methods?
  2. Can I check the checkbox when I click the button? Or a few? (i.e. only mark, when pressed again, so that the marks do not fly off)
  • five
    if i'm not mistaken, the element may have several classes, separated by spaces. - system29a
  • Do you want to use pure javascript or are you ready to use frameworks (for example jquery)? - Chad
  • yes to me at least some be an example. adequate. then I will apply first, secondly I will learn a lot - sergey

2 answers 2

If on jquery, you can do this:

$('.RowClass').click( function(){ $(this).find(":checkbox").attr("checked","checked");//выделение всех чекбоксов на кликнутом контейнере, снять выделение через removeAttr("checked") }); 

html doing something like:

 ... <tr class="RowClass"><td><input type="checkbox"/></td><td></td></tr> ... 

You can also not a table a diva or something else. The bottom line is that we hang on elements with a class and on a click we are looking for checkboxes inside it ...

in order to remove / install - complicate the function of a click - add, say, to $ (this) .attr ("state") - the desired state and, depending on it, remove or put checks (do not forget to update the state attribute)

Yes, it is in the current implementation that there will be a feature - when clicking on the checkbox, the click will also work and check all the check boxes. I think you will figure out how to avoid it - there are plenty of options. But if you can not cope, contact, prompt.

  • did just that. Although the code itself is not to fantasize. eats but jq hooked up. it didn't work for me. now I understand what's the matter - sergey
  • It was sealed, the class tr naturally <tr class = "RowClass" ... and not ". RowClass" - Chad

Checking and vice versa will be done by anyone to make a reaction to the area. Wrap a check in the label with something like this: <label for = "check1"> <input id = "check1" type = "checkbox" /> </ label>

  • works, but if the input itself is inside the label - 8- does not work ( - sergey