I am trying to load the content of specific element from the page loaded with $.ajax that also contains some javascript functions (like form validations, etc.) that I would like to execute, here is a quick sample:
$.ajax({
url : 'sample.html',
success : function(data) {
$('body').append($(data).filter('#data')); //does load the content of an element but javascript wont work.
//$('body').append(data); this works but I dont need an entire page
}
});
sample.html content:
<!DOCTYPE html>
<html>
<head></head>
<body>
trash trash trash
<div id="data">
<script>console.log('javascript works even from ajax called content');</script>
some more sample data to load
</div>
trash trash trash
</body>
</html>
Maybe in your opinion I should not use any javascript inside ajax loaded content... but then I am not sure how to access it.