Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open DOM Element with Featherlight on Page Load?

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();
like image 294
Matt McManis Avatar asked Feb 27 '17 01:02

Matt McManis


People also ask

How to find HTML elements in the Dom?

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":

How do I edit the Dom on the fly?

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>.

Why wait for DOM elements to show up in modern browsers?

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.

How to access any HTML element in a document with JavaScript?

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.


1 Answers

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>
like image 168
gyre Avatar answered Sep 28 '22 19:09

gyre