logo
Search:

Login:


Forgot Details? Sign-up

forum >> Programming questions >> JavaScript / AJAX

mixing javascript and html

Posted Feb 22 2012 at 1:35 PM by
Brian McFeeters (brian)
I am trying to write a program with a for loop (javascript command), but inside the loop I want to use some html tags -- namely, a ... ...so I can have the user select a letter. Is there a way to write html inside a javascript command section?
AuthorMessage
Andy
Posted: Feb 23 2012 kl. 8:50 AM

You can have javascript modify part of the HTML code using the innerHTML feature, but you can't (at least easily) build something complicated like a structure on the fly.

Normally, the entire page needs to be in the client's browser before any action happens. This means the entire HTML framework is complete before JavaScript code executes. You can use JavaScript to modify existing HTML, and to add new elements in, but you can generally only respond to code that's already in place.

Here's a simple example of creating HTML on the fly with JavaScript:
http://aharrisbooks.net/demo/makeStuff.html

Hope this helps!

-Andy