Dina
Dina

Reputation: 621

Remove HTML attribute before rendering

Is it possible to remove src attribute for each img tag before image is fetched ? I want to change image fetching behavior.

What I did:

$('img').each(function() {
    var elem = $(this);
    elem.removeAttr('src');
    // ... my custom actions
});

What happened: Image is fetched, before src attribute is removed :/

Thanks

Upvotes: 1

Views: 534

Answers (1)

Huangism
Huangism

Reputation: 16448

If your src is in the markup then it will fetch before your js execute. Simply don't use src attribute, put the src in say data-src, then grab it with js and do what you want to do.

Upvotes: 2

Related Questions