4

Is there anyway to append some html content from a file in Jquery?

I know you can use load() in jquery to replace the entire content within an element.

but I wonder if I can conditionally use append('url') to add extra content into an element in Jquery

4 Answers 4

5

You could try this:

$.get('/someurl', function(result) {
    $('#someElement').append(result);
});
Sign up to request clarification or add additional context in comments.

Comments

3

So you are trying to append dynamic content? Try something like this:

$(document).ready(function(){
  $.get('<URL>', function(data){
    $(<contentelement>).append(<either entire data element, or do some operations on it>);
  });
});

Comments

0

Yes you can. append() literally appends something to the end of an element.

Comments

0

Another way is to do a two step process, i.e

onclick='$("#id1").append("<div id=\"id2\"></div>"); $("#id2").load("content.php");'

This also works to prepend content from another url too.

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.