Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML

Daniele Fusari
Daniele Fusari
40,669 Points

Is 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

Not 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 divs).

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.