I'm having trouble getting a Featherlight modal window to show content on page load.
https://github.com/noelboss/featherlight/#usage
https://jsfiddle.net/axxdy4we/
Open Featherlight DOM with Link
<a href="#" class="my-content" data-featherlight="<p>My Content</p>">Open some DOM in lightbox</a>
This link loads html content from the data-featherlight
attribute
Clicking the link will load "My Content".
On Page Load
$.featherlight($('.my-content'), {});
This only loads whats between the <a>
tags, "Open some DOM in lightbox
".
How to call "My Content" from the data-featherlight
attribute on page load?
I need to have the html inside the data-featherlight
, not outside in a div.
I thought it might be something like
$('.my-content').featherlight();
$('.my-content').featherlight.current();
Finding HTML elements by HTML object collections Finding HTML Element by Id The easiest way to find an HTML element in the DOM, is by using the element id. This example finds the element with id="intro":
You can edit the DOM on the fly and see how those changes affect the page. To edit a node's content, double-click the content in the DOM Tree. Right-click Michelle below and select Inspect. In the DOM Tree, double-click Michelle. In other words, double-click the text between <li> and </li>.
Because no matter what, by the next render frame, whether it comes in a 60th of a second, or a minute, the element will have been rendered. And that's how you properly wait for DOM elements to show up in modern browsers.
You should now feel confident to access any HTML element in a document with JavaScript through the DOM. The Document Object Model, usually referred to as the DOM, is an essential part of making websites interactive. It is an interface that allows a programming language to manipulate the content, structure, and style of a website.
Call .featherlight()
on your content to ensure that the modal window is configured, and then use jQuery to .click()
it right after the page loads:
$('.my-content').featherlight().click()
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://noelboss.github.io/featherlight/release/featherlight.min.js"></script>
<a href="#" class="my-content" data-featherlight="<p>My Content</p>">
Open some DOM in lightbox
</a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With