Upon further reading, according to SA's suggestion, I understood your question.
I would try to give you another answer:
The thing you are trying to achieve is not possible. Similar thing is very much possible in PHP though. But if you have section that need to be showed based on various function and conditions then I would suggest you to look through the option of hiding and showing or creating and destroying the object based on function call.
--text, written below, seems unrelated--
I do not think you have explained your question good enough to have an answer.
I will explain the reason, that I have understood.
Say, your current browser received a data from server like below:
<script ...="">
function process_new_div(){
...
}
process_new_div();
</script>
<div id="new_div">
content.
</div>
Current page will load this portion of data and then process the received code. This issue will only occur with AJAX.
Solution:
In general, most of the developer use JQuery to solve this issue. JQuery will dissect the received data and process the Script for you. If you are not using jquery
here is an example below
var result = received_data.match(/<script>(.*?)<\/script>/g).map(function(val){
return val.replace(/<\/?script>/g,'');
});
</script>
In order to run extracted javascript:
run eval function. Try the following example in firefox or Chrome browser:
eval("x=10;alert(x)");
Anyway, if this is not what you want let us know.