1

I need to replace one div with another and also i need another container to be removed. Please, see my code:

<a id="load-more" href="#">
<div class="text">Load more</div>
<div id="infscr-loading">
<img alt="Loading..." src="../loading_small.gif" style="display: none; ">
<div">No more posts to load</div>
</div>
</a>

I need this:

<span class="text">Load more</span>

replace with this:

<div">No more posts to load</div>

So, my result should be:

<a id="load-more" href="#">
<div">No more posts to load</div>
<div id="infscr-loading">
<img alt="Loading..." src="../loading_small.gif" style="display: none; ">
</div>
</a>

It's possible to do?

1
  • Yes, it's possible. What have you tried? Commented Jul 19, 2012 at 19:55

3 Answers 3

6

Did you try:

$('.text').replaceWith(...);

Docs at http://api.jquery.com/replaceWith/

Sign up to request clarification or add additional context in comments.

Comments

1

Your markup has an error in the <div"> tag, probably you accidentally removed the class name or id. I'll assume the replacement div has an id attribute.

To change the contents of the <div class="text"> bit you need to do:

$('div.text').replaceWith($('#replacement'));

This both eliminates the text div and moves the #replacement div to the position of the text div.

Comments

1
$('div.text').replaceWith($('#replacement').html());

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.