Showing hidden elements based on having something in a field within a dataset

Hi all! I’m having trouble with an aspect of my code. I have a news data collection, and some of the articles have audio or file to download and some do not. I want to show these elements on my page when that field is filled in the collection. I was able to execute one element perfectly, but I can not figure out how to show the other element. Here is my code. It shows an error thatline 11 .onReady is not a function. What am I missing??? Thank you

Please post your code in a code block as it is very difficult to deal with in a screenshot.

Line 11 has an error on the onReady() function since it is “outside” of the page $w.onReady() function and therefore inaccessible. See $w.onReady() :: a guide for the perplexed to better understand what the page onReady() function does and what it’s for.

Furthermore, it is incorrect to define more than one dataset onReady() function. It is defined once, in the page’s onReady() to ensure that the dataset is ready before trying to use it.

What is it you are trying to accomplish?

Perhaps this is sort of what you need:

$w.onReady(function () {
   $w('#newsDataset').onReady(() => {
      let item = $w('#newsDataset').getCurrentItem();
      if(item.pdf !== undefined || item.pdf !== null) {
      if( !== undefined || !== null) {

Disclaimer: This has not been tested, but it’s sort of close to what I understand that you are trying to do.