I'm trying to append an external html content (div plus some text inside just for testing) this way:
$.get("banner.html", function(data){
$(this).children("div:first").append(data);
});
That seems to be pretty simple... but it does not seem to work. Any idea? Thanks!
To load external HTML into a <div>, wrap your code inside the load() function. To load a page in div in jQuery, use the load() method.
Add New HTML Contentappend() - Inserts content at the end of the selected elements. prepend() - Inserts content at the beginning of the selected elements. after() - Inserts content after the selected elements. before() - Inserts content before the selected elements.
Use html instead of append:
$.get("banner.html", function(data){
$(this).children("div:first").html(data);
});
i'm not sure what you're expecting this
to refer to in your example.. here's an alternative method:
<html>
<head>
<script src="http://code.jquery.com/jquery-1.6.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$.get("banner.html", function (data) {
$("#appendToThis").append(data);
});
});
</script>
</head>
<body>
<div id="appendToThis"></div>
</body>
</html>
You can use jquery's load function here.
$("#your_element_id").load("file_name.html");
If you need more info, here is the link.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With