I have a varying number of elements with the same class name:
I want to replace each of these with a new set of elements with the same class name, but there could be more or fewer elements:
If I use `$('p.test').replaceWith('new content')`, it will replace each element with the content so I can't do that.
What is the best way to accomplish this?
EDIT (another explanation):
So I have these elements on the page:
Then, I dynamically retrieve a new set of elements (a varying number of them) that have the same class name (and maybe some other class names). For example:
In the above example, I want the first three `
` elements to be gone. And in their place should be the 2 dynamically retreived `
Keep in mind the number of elements of either set can vary.
Why do they have the same class? If you want each to have different elements you should use different id's. Or append new elements on the fly with jquery. I dont quite understand your question, could you please explain a little better? Thanks :)
以上就是How to use jQuery replaceWith to replace varying number elements的详细内容，更多请关注web前端其它相关文章！