What's the difference between jQuery's replaceWith() and html() functions when HTML is being passed in as the parameter?
Jquery – What’s the difference between jQuery’s replaceWith() and html()
jquery
Related Question
- Javascript – event.preventDefault() vs. return false
- Jquery – the difference between jQuery: text() and html()
- Jquery – What’s the difference between jquery.js and jquery.min.js
- Javascript – window.onload vs $(document).ready()
- Javascript – Find object by id in an array of JavaScript objects
- Javascript – How to return the response from an asynchronous call
Best Solution
Take this HTML code:
Doing:
Will result in:
Doing:
Will result in:
So html() replaces the contents of the element, while replaceWith() replaces the actual element.