I currently count the number of visible rows in an html table, before and after applying a search. The result count is placed into the textbox by an onclick event of the button "results". Is it possible to get the result count directly in the text box, updated on change of the number of visible rows?
html:
results
The function works fine onclick of the button. Textbox onclick also works, but I would like to avoid the clicks and have the value auto-updating in the textbox.
2
Answers
You can use a MutationObserver to monitor changes to the tbody element and then check the number of visible rows. The one quirk here is that CSS changes can’t be checked, so I used an HTML attribute to represent visibility which will be monitored by the observer.
it would be helpful if you share also the JS code so we can see which one we can modify to achieve the result you need.
Based on your scenario, what you need to do is to move the code from the onclick of the results button to the function where you generate the rows (after generation of rows).
Assuming that your function for the generation of rows is search(), this will be flow: