Reputation: 31
I want to pass some files path into a JavaScript or Jquery function, so this can display those files (HTML files) into a div when clicking an a
tag.
its possible?
something like this:
<script>
$(document).ready(function loadcontent(pathfile){
$('#content').load("pathfile");
});
</script>
The div:
<div id="content">
HTML FILE HERE
</div>
Upvotes: 0
Views: 587
Reputation: 337626
It depends on the path. If it's a local path (eg. file://C:/foo.txt
) then no, you cannot do this for security reasons.
If it's a relative path to a public resource held on your own server (eg. /folder/file.html
) then yes, this is possible. In your case you would just need to fix your syntax to create a valid function and provide the argument to load()
:
jQuery($ => {
loadContent('/path-to-your/file.html');
});
function loadContent(path) {
$('#content').load(path);
}
Upvotes: 1