How to call a jQuery function on another jQuery function?
I am trying to refresh the contents of a div using the jQuery setInterval and load functions. So far, everything is working fine, except it loads the full div, including the div tags. I only want the contents of the div to be reloaded/refreshed. I tried adding the jQuery function text(), but it isn't working, or maybe I am writing up the wrong syntax.
$('#numberOfTries').load('index.php #numberOfTries').text(); does not work.
This is what I have so far, which works but loads the entire div with the div tags:
HTML of Index.php (Top)
<div id="numberOfTries"><?php echo $numberOfTries; ?></div>
JS of Index.php (Bottom)
<script src="assets/js/jquery.min.js"></script>
<script>
$(document).ready(function() {
setInterval(function() {
$('#numberOfTries').load('index.php #numberOfTries');
}, 1000);
});
</script>
The script loads the full div, which is <div id="numberOfTries">50</div>, but I only want to load the content of the div, which is 50.
When the script runs, the HTML ends up looking like this:
<div id="numberOfTries">
<div id="numberOfTries">50</div>
</div>
But I only want it to look like this:
<div id="numberOfTries">
50
</div>
I think my syntax $('#numberOfTries').load('index.php #numberOfTries').text(); is incorrect.
Please let me know if clarification is needed.
$('#numberOfTries').load('index.php #numberOfTries');basically reloads<div id="numberOfTries"><?php echo $numberOfTries; ?></div>, but it loads the entire div like so:<div id="numberOfTries"><div id="numberOfTries">50</div></div>, while I only want it to load<div id="numberOfTries">50</div>', which is only50` the content of the div..load()is loading the content of the page you're passing as a parameter, but just the element which ID isnumberOfTries, and adding it to the same div.