Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Daniele Fusari
40,669 PointsIs there an HTML "eg open", attribute for .showModal()
Is there an attribute like open. That opens it the same as .showModal()
.show() = open
.showModal() = attribute?
1 Answer

Alan Brown
20,382 PointsNot sure of the context here. But this would depend on whether you are using a dialog
element in your html, or rolling your own modal (with div
s).
The dialog
element has an open
property. Read about it here https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dialog
When rolling your own (and for whatever reason are choosing to not use dialog
) it is pretty common to store state on the element with either a data attribute (eg: data-open
) or a class (eg: is-open
or is-active
). You would then manually update the state whenever you call functions to open or close the modal.
Daniele Fusari
40,669 PointsDaniele Fusari
40,669 PointsThank you.