is it possible to do an append without specifying a selector
so in html I have an arbitrary element and inside that I call a function that will append content inline
so html looks like this
<!-- stuff before -->
<fieldset>
<script type="text/javascript">
$(document).ready(function(){
get_content();
});
</script>
</fieldset>
<!-- stuff after -->
then in a js file that gets loaded I have the get_content() function like this
function get_content(){
$.append('<div id="some_id"></div>');
}
currently I get an error saying append is not a function
JavaScript won’t write out code in the way you’re trying to do it here. JavaScript is separate from content and works with the entire document, so placing JavaScript in your markup where you want it to appear won’t do anything unless you use
document.write(...), which is considered one of the worst things you can use in JavaScript.Instead, you should do this:
Your markup would look like this:
Then your script could look like this (it can go anywhere)
And then you can use your
get_content()function to append stuff.