0

Here's an example doc structure

<div>
    <div id="1" class="to-replace"></div>
    <div id="2" class="to-replace"></div>
    <div id="3" class="to-replace"></div>
</div>

What I want to do is replace #1, for example, with whatever I retrieve from the ajax call (I'm not using JSON because the request is extremely small and it didn't seem worth it. Plus, the site is mostly for my personal use). I know I can use JQuery .load() to replace the contents, but there must be some easy way to replace the whole thing.

3
  • 1
    See stackoverflow.com/questions/16987135/… Commented Jun 26, 2013 at 14:12
  • 1
    Are you coding in HTML5? If you aren't, your id attributes are invalid. They must not begin with a number. Commented Jun 26, 2013 at 14:21
  • @Ghillied I'm not, but it was just an example. I didn't actually name them 1, 2, 3. Thanks though. Commented Jun 26, 2013 at 14:26

2 Answers 2

5

You can use the replaceWith jquery function to replace an element:

    $("#1").replaceWith("bla");
Sign up to request clarification or add additional context in comments.

Comments

3
$.get(url,function(data){
   $("#1").replaceWith(data);
}); 

where url is the url to whatever you want to get and data is the data that is returned

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.