0

I have a separate file called lastrun.html that simply contains a datestamp. I want that to display in my index.html in the right spot.

I am using

 $(document).ready(function() {
                    $("#lastrun").load("lastrun.html");
 });

and then in my html body section I have:

<p>Last run on <div id="lastrun" style="display:inline"></div></p>

The expectation was:

Last run on June 05 2017, but instead it does:

Last run

June 05 2017

How do I get the date to appaer on the Last run line?

archcutbank
  • 419
  • 1
  • 6
  • 17

3 Answers3

2

Change div to span

<p>Last run on <span id="lastrun" ></span></p>

For a better explanation of difference between div and span you check out this answer here

Peter
  • 1,006
  • 7
  • 15
  • got my vote as it is a correct solution, but it would be better if you posted an explanation of why that would work and why the original does not. – Gabriele Petrioli Sep 22 '17 at 17:12
1

div is not allowed inside a p. This causes the p to close, followed by the div and then another empty p.

So your html, even before the ajax call, is rendered by the browsers like this

<p>Last run on </p>
<div id="lastrun" style="display:inline"></div>
<p></p>

So you need to either use an allowed element inside the p, like a span or use a div for the outer element instead of the p.

<p>Last run on <span id="lastrun" style="display:inline"></span></p>

or

<div>Last run on <div id="lastrun" style="display:inline"></div></div>
Gabriele Petrioli
  • 191,379
  • 34
  • 261
  • 317
0

I've created a jsfiddle with 2 techniques for loading content.

$("#lastrun").load('lastrun.html'); 

The above is identical to your example. The div tags shouldn't affect this however you be able to debug with a more traditional ajax request:

$.get('lastrun.html', function(aResponse) {
  $("#lastrun").html(aResponse);
}).fail(function(jqXHR, textStatus, errorThrown) {
  console.error(arguments);
  $("#lastrun").html(errorThrown);
});

This should help you determine whether there is a problem with the request url itself.

Max Bilbow
  • 110
  • 7