7

Instead of lazy loading image alone,i need to add lazy load for entire div element in my page.

Can you anyone help me out with some plugins or own js code.

1

1 Answer 1

3

You can use this plugin. Its helpful and will do the trick for you.

https://github.com/emn178/jquery-lazyload-any

Just use this script as shown in documentation.

<div id="you-want-lazyload">
  <!--
    <p>Anything you want to lazyload</p>
  -->
</div>

JavaScript

$('#you-want-lazyload').lazyload(options);

Hope it will help.

Edit

HTML Attribute Style

<div id="you-want-lazyload" data-lazyload="&lt;p&gt;Anything you want to lazyload&lt;/p&gt;">
</div>

Script Style

<div id="you-want-lazyload">
  <script type="text/lazyload">
    <p>Anything you want to lazyload</p>
  </script>
</div>
Sign up to request clarification or add additional context in comments.

4 Comments

the value for child elements of div tag will be binded from datasource. but using this plugin inner elements should be commented <!-- --> .
This is just an example I have given, You can check the documentation there are different way of doing this. Let me update my answer for you. @mano
fine. for me its works with script style. thanks a lot man @Smit Raval
This is a jQuery example. Not a javascript example. It should say as much. Newer users will find this answer confusing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.