What is the difference between Jquery\'s .clone() and .html() functions?
Jquery documentation states:
The .clone() method performs a deep copy of
.clone() can also we used in cases where we need to use a piece of code multiple times on out html page. Say we need to include the above code to create star rating multiple times.
So in this case if we want this same code to be applied multiple times in out html , we can use two ways:-
1. var ratingStar = $('.rating-stars').html();
2. var ratingStar = $('.rating-stars').clone();
Advantage of using .clone() is that all the styles applied to the elements in .rating-stars will be present as .clone() give back a jquery object while .html() will simply return an string with no styles attached.