Dynamic HTML via embedded Javascript

I wandered how to do this (embed js in the middle of an HTML doc, and dynamically write HTML from withing a js function. Found this while looking for something else 🙂

<td style=”background-image:url(‘/images/sub_header_bckgrnd.gif’); background-repeat:x-repeat” valign=”top” width=”99%”>
<script>
var minealt = ‘My Alt Text’;
document.write(‘<img src=”/images/someimage.gif” alt=”‘+minealt+'” title=”” border=”” hspace=”20″ vspace=”18″>’)
</script>
</td>

Note the use of a variable and string in document.write. The script is embedded where we want the dynamic HTML to go.

Advertisements

Feel Free to Comment (Name/Email/Website optional):

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: