# Use JavaScript to hide/show views if text found on page

**URL:** <https://forums.knack.com/t/use-javascript-to-hide-show-views-if-text-found-on-page/10129>\
**Category:** Show & Tell\
**Created:** [September 21, 2016, 2:39pm UTC](https://forums.knack.com/t/use-javascript-to-hide-show-views-if-text-found-on-page/10129 "2016-09-21T14:39:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![TaylorSnow83029](https://avatars.discourse-cdn.com/v4/letter/t/7bcc69/32.png) [@TaylorSnow83029](https://forums.knack.com/u/TaylorSnow83029)\
**Post date:** [September 21, 2016, 2:39pm UTC](https://forums.knack.com/t/use-javascript-to-hide-show-views-if-text-found-on-page/10129/1 "2016-09-21T14:39:44Z")

</div>

Thought I would share this with the community since it took me a bit of time to learn this couldn't be done through the Knack interface. My use for this was a staff member would choose options when building a new agreement. Based upon the options previously selected options I needed to hide or show a editable table for the end user to update.&nbsp;

In the example below the view\_1 is where my selections were displayed in text via a field. 'keyword' is the option text the JS is looking for. view\_2 is the view it will show if that text is found in view\_1. I used CSS to hide all tables on the page and the JS below to show them if the text was found.&nbsp;

$(document).on('knack-view-render.view\_1', function(event, page) {

&nbsp; $('span').each(function(){

&nbsp; &nbsp; var text = $(this).text().toLowerCase();

&nbsp; &nbsp; if (text == 'keyword') {

&nbsp; &nbsp; &nbsp; &nbsp; $('#view\_2').show();

&nbsp; &nbsp; }

&nbsp; });

&nbsp;&nbsp;

});

I am sure some one has an easier or smarter way to to this, but it was the only option I had in my bag of tricks. I hope this helps someone else.&nbsp;

---

<div class="post-metadata">

**Author:** ![TCAdmin78313](https://avatars.discourse-cdn.com/v4/letter/t/3bc359/32.png) [@TCAdmin78313](https://forums.knack.com/u/TCAdmin78313)\
**Post date:** [September 26, 2016, 9:23pm UTC](https://forums.knack.com/t/use-javascript-to-hide-show-views-if-text-found-on-page/10129/2 "2016-09-26T21:23:21Z")

</div>

Hi Taylor,

Great find! I've actually found a good solution for hiding entire views based on if there's no data in a table, and it can easily be manipulated to work with other non-table views, I believe. Thought I'd share.

&nbsp;

```
/*Hide Empty Tables*/

$(document).on(‘knack-view-render.table’, function (event, view, data) {  
$(’.kn-td-nodata’).parents(’.kn-view’).hide();  
});
```

Thanks,

Jared
