chimniii



Sometimes we need to create dynamic dom element they might take reference of existing dom element.  Let's take some scenario we want to create widget which have same looks and functionality and we want to make it available all the pages of our website. in such a scenario we can't write code for each of the html page for the samething which we already created in previous page(widget). In order to solve this issue we use jquery clone function, below is the example of the clone object, in order to make it available we will store it in localstorage which is html5 features to store the data and object.

lets take a look of html file

<html>
</body>
<div class="realobject">
<div class="child_object0"></div>
<div class="child_object1"></div>
</div>
</body>
</html>

lets clone the realobject 

<script type="text/javascript">
$('document').ready(function(){
var clone_object=$('.realobject').clone()
localstorage.setItem('clone',clone_object.html)


})
</script>

In above script code we define clone_oject and save into localstorage now you can access same div just calling function and append it to another html file
<script>
var clone_object_referee=localstorage.getItem('clone')
$('body').append(clone_object_referee)
</script>

Happy coding....

Recent Articles
New service launch
chimniii.com