Search code examples
jquerycheckboxhtml-tableclojurescript

Finding index of table rows with checked checkbox


I have a html table where the first cell of each row contains a checkbox. I would like to get the index of each row with a checked checkbox. I have access to JQuery as js/$

This is what I have so far, but it only returns Javascript object from which I cannot extract the index(es).

(-> (js/$ "#table tr")
    (.has ":checkbox:checked")
    (.find "td:eq(1)")
    (.each (fn [e] (.text (js/$ e)))))

Solution

  • Based on Ozan's Javascript answer I was able to come up with this solution:

     (.map js/$ (-> (js/$ "#table tr")
                (.has ":checkbox:checked")) (fn [tr] (.index (js/$ tr))))