Demo For: jQuery html Examples

This is MY DIV 1
This is MY SPAN 1

Conclusion

When using the jQuery .html() method and performing an act upon a common attribute to , such as the class name, only the first matched element's html content will be fetched when you are trying to get the data, othwerwise data for all matched elements will be overwritten. Hence when you click the "Get HTML Content using Class" button you will see that only the div's content is fetched. When you click the "Replace HTML Content using Class" button, you will see that the data for both the div and the span is overwritten.