Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add a class/selector to <img> when using <picture> #244

Open
Brodiero opened this issue Jul 31, 2020 · 1 comment
Open

How to add a class/selector to <img> when using <picture> #244

Brodiero opened this issue Jul 31, 2020 · 1 comment

Comments

@Brodiero
Copy link

Not an issue but I'm struggling to find how to do this. In using the picture/source/img responsive setup I need to add a class directly to the element (for a different GSAP array).

I've searched the issues here and haven't found success, can anyone help?

TIA

@svirmi
Copy link

svirmi commented Jul 13, 2021

I have added class to dynamically created target image:

const pictureTagObserver = lozad("picture.lozad", {
threshold: 0.1,
load: function(el) {
const img = document.createElement("img");
const src = "https://imagesrc.io"
img.setAttribute("src", src);
img.setAttribute("class", el.getAttribute("data-class"));
el.appendChild(img);
}
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants