user743253
user743253

Reputation: 3

.innerHTML from .js file?

i want to print all text from .js file to div

document.getElementById('cart-status').innerHTML = "/numberOfcart.js" 

Upvotes: 0

Views: 665

Answers (2)

Bakudan
Bakudan

Reputation: 19492

Directly displaying the the contents of js file by JavaScript is not possible (or I don`t know, if somebody knows a way - welcome). So by PHP:

$file = file_get_contents( 'script.js' );
echo "<pre>" . htmlentities ( $file ) . "</pre>";

With an ajax callback to the php script, set to the div.

Upvotes: 0

m2m
m2m

Reputation: 23

You could use jQuery to do something like this:

$.get('/numberOfcart.js', function(data) {
  $('#cart-status').text(data);
}

but you are simply loading in the .js file, not running it.

Upvotes: 2

Related Questions