Skip to content

Commit

Permalink
support for toggling by CSS selector, not only id (#210)
Browse files Browse the repository at this point in the history
this is useful eg. for controls manually rendered as table cells `<td>` which have only `<tr>` valid parent .. if there are multiple cells within table row toggling via `id` is not feasible (it would toggle all the cells in that row).
  • Loading branch information
Ciki authored and dg committed Feb 11, 2019
1 parent 11e21e5 commit 6a1100d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/assets/netteForms.js
Original file line number Diff line number Diff line change
Expand Up @@ -655,9 +655,12 @@
* Displays or hides HTML element.
*/
Nette.toggle = function(id, visible, srcElement) { // eslint-disable-line no-unused-vars
var elem = document.getElementById(id);
if (elem) {
elem.style.display = visible ? '' : 'none';
if (/^\w+$/.match(id)) { // id
id = '#' . id;
}
var elems = document.querySelectorAll(id);
for (var i = 0; i < elems.length; i++) {
elems[i].style.display = visible ? '' : 'none';
}
};

Expand Down

0 comments on commit 6a1100d

Please sign in to comment.