Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load code into HTML using JQuery?

I know it's possible, and I've looked at numerous examples. And I'm afraid I already know the answer to my question, but perhaps I'm missing something. I was thinking that this does not work because I am running this code locally, and not on a server.

In my head tag:

<script type="text/javascript" src="jquery-1.5.js"></script>

<script type="text/javascript">
    $(document).ready(function() {
        $("#test").load("test.html");
        } );
</script>

In my body tag:

<div id="test"></div>

My external code (inside 'test.html")

<div>This is what you should be seeing!</div>

Shouldn't this work? Additionally, in my external html document, do I need set it up with all the extra tags, so that the document would look like:

<html>
    <head>
        <title>
        </title>
    </head>
    <body>

<div>This is what you should be seeing!</div>
</body>
</html>

All my files are in the same directory.

Thanks.

like image 586
Hanna Avatar asked Jun 05 '26 16:06

Hanna


1 Answers

Well your code should work on webserver! Please let me know if you are doing it from you desktop.

<script src="jquery.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
    $("#test").load("./test.html"); //  also try /test.html
    } );
</script>
<div id="test"></div>
like image 195
Santosh Linkha Avatar answered Jun 08 '26 00:06

Santosh Linkha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!