Newbie script not working- project delayed

In Adrian’s code it is being passed into the toggleDisclosure function when the button is clicked:

onclick=toggleDisclosure(this.id)

You are calling funcRunTwo on the button click and not passing in anything.

Adrian is a top accessibility expert and this is a very good example to reference but he is just showing you how to make a disclosure widget accessible, I don’t think he created this example to be directly integrated into someone else’s code. So make sure you understand exactly what his code is doing because a simple copy/paste is probably not going to work.

I’m grateful for all these important details. Printing out your email and also @bbsmooth Bruce’s. Homework!
Tomorrow I’ll get back on the project.

Thank you so much. I’ll step up to this again tomorrow. A part of how this became so much copy/paste is that most my experience is based on whatever clients asked me for, which usually meant lots of CSS where I build from scratch (except Bootstrap etc). My computer classes were so long ago that the technology (COBOL, Assembly) isn’t directly relevant to web development. Time to sign up for a JS class online.

Sounds like an HTML <details> element. :thinking:

I’ve done a bit more reading. My preliminary response is that my toggleDisclosure(btnID) is like the first example, and the fncShowHideTxt() is like the third example. I excluded the second example because of its use of const which is probably “block scope” and doesn’t appear in my code. I also bookmarked that curriculum link.

This means the variable btnID you are using as an argument to the toggleDisclosure function, is not inside the scope of the fncShowHideTxt function.

Summary
function funcRunTwo() {
  // btnID doesn't exist inside funcRunTwo
  toggleDisclosure(btnID);
  fncShowHideTxt();
}

You can have btnID as a parameter on funcRunTwo and pass the value as an argument.

Summary
function funcRunTwo(btnID) {
  // btnID does exist inside funcRunTwo as a parameter
  // its value is the string 'someID'
  toggleDisclosure(btnID);
  fncShowHideTxt();
}

funcRunTwo('someID');

Or you can have the btnID variable live in an outer scope which makes it accessible to the function.

Summary
const btnID = 'someID';

function funcRunTwo() {
  // btnID exist in an outer scope and is accessable inside the funcRunTwo function
  // which means you can pass it as an argument to the toggleDisclosure function
  toggleDisclosure(btnID);
  fncShowHideTxt();
}

funcRunTwo();

var, let, or const doesn’t really matter for what we are talking about here as the variable lives in a top-level scope and not inside a code block. If you plan to reassign the variable use let, otherwise you const, avoid var.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.