Jump to content

question on innerHTML

Swiebertjeee
Go to solution Solved by orange,

I think You're running the script before the HTML content is loaded, so you need to move the <script> to the end of your HTML document, before </body> or use JQuery document.ready.

And if your script is not inside a function, there shouldn't be a return value.

this is my code right now:

 

HTML

<table>                            <tr>                                 <td><div id="day1"></div> </td>                            </tr>                            <tr>                                 <td> </td>                            </tr>                     </table>

JS

	var dag1 = "Test1";	document.getElementById("day1").style.display = "block";	document.getElementById("day1").innerHTML = dag1;	return false;

but It's not working,

Beneath this mask there is an idea, and ideas are bulletproof.

Link to comment
Share on other sites

Link to post
Share on other sites

-snip-

What exactly doesn't work..?

Does the html or JS not work?

"We're all in this together, might as well be friends" Tom, Toonami.

 

mini eLiXiVy: my open source 65% mechanical PCB, a build log, PCB anatomy and discussing open source licenses: https://linustechtips.com/topic/1366493-elixivy-a-65-mechanical-keyboard-build-log-pcb-anatomy-and-how-i-open-sourced-this-project/

 

mini_cardboard: a 4% keyboard build log and how keyboards workhttps://linustechtips.com/topic/1328547-mini_cardboard-a-4-keyboard-build-log-and-how-keyboards-work/

Link to comment
Share on other sites

Link to post
Share on other sites

What exactly doesn't work..?

Does the html or JS not work?

Well the code doesn't work. I tested the JS with an alert so It is loading on the html. but the div "day1" stays empty while I wanted it to show the string from "dag1"

Beneath this mask there is an idea, and ideas are bulletproof.

Link to comment
Share on other sites

Link to post
Share on other sites

I need it to show in the div so in that case I can put up 1 JS file which people can easily rewrite (for example tour dates) which can show up on every html page.

Beneath this mask there is an idea, and ideas are bulletproof.

Link to comment
Share on other sites

Link to post
Share on other sites

I think You're running the script before the HTML content is loaded, so you need to move the <script> to the end of your HTML document, before </body> or use JQuery document.ready.

And if your script is not inside a function, there shouldn't be a return value.

Link to comment
Share on other sites

Link to post
Share on other sites

I think You're running the script before the HTML content is loaded, so you need to move the <script> to the end of your HTML document, before </body> or use JQuery document.ready.

And if your script is not inside a function, there shouldn't be a return value.

I did place it in the <head> so thank you for this :)

Beneath this mask there is an idea, and ideas are bulletproof.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×