<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Random Snippets &#187; document object model</title>
	<atom:link href="http://www.randomsnippets.com/tag/document-object-model/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.randomsnippets.com</link>
	<description>Random Snippets of Code and Ideas for any Web Developer</description>
	<lastBuildDate>Wed, 05 Aug 2009 14:32:02 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Dynamically edit font styling of HTML content via JavaScript</title>
		<link>http://www.randomsnippets.com/2008/02/24/dynamically-edit-font-styling-of-html-content-via-javascript/</link>
		<comments>http://www.randomsnippets.com/2008/02/24/dynamically-edit-font-styling-of-html-content-via-javascript/#comments</comments>
		<pubDate>Mon, 25 Feb 2008 05:12:38 +0000</pubDate>
		<dc:creator>Knix</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[color background]]></category>
		<category><![CDATA[div id]]></category>
		<category><![CDATA[document object model]]></category>
		<category><![CDATA[dynamic]]></category>
		<category><![CDATA[Dynamically]]></category>
		<category><![CDATA[dynamicContent]]></category>
		<category><![CDATA[html javascript]]></category>
		<category><![CDATA[javascript onclick event]]></category>
		<category><![CDATA[size font]]></category>
		<category><![CDATA[styling]]></category>

		<guid isPermaLink="false">http://www.randomsnippets.com/2008/02/24/dynamically-edit-font-styling-of-html-content-via-javascript/</guid>
		<description><![CDATA[The Document Object Model (DOM) allows for dynamic styling because it makes all HTML elements and attributes readily accessible using JavaScript.  Here is a simple demo of how powerful this technology can be:

Demo
Hello world!









Here is the JavaScript code that makes all this possible:


&#60;div id=&#34;dynamicContent&#34;&#62;Hello world!&#60;/div&#62;
&#60;input type=&#34;button&#34; onClick=&#34;document.getElementById('dynamicContent').style.fontWeight = 'bolder';&#34; value=&#34;Bold&#34;&#62;
&#60;input type=&#34;button&#34; onClick=&#34;document.getElementById('dynamicContent').style.fontWeight = 'lighter';&#34; [...]]]></description>
			<content:encoded><![CDATA[<p>The Document Object Model (DOM) allows for dynamic styling because it makes all HTML elements and attributes readily accessible using JavaScript.  Here is a simple demo of how powerful this technology can be:</p>
<fieldset>
<legend>Demo</legend>
<div id="dynamicContent">Hello world!</div>
<p></p>
<input type="button" onClick="document.getElementById('dynamicContent').style.fontWeight = 'bolder';" value="Bold">
<input type="button" onClick="document.getElementById('dynamicContent').style.fontWeight = 'lighter';" value="Lighter">
<input type="button" onClick="document.getElementById('dynamicContent').style.fontStyle = 'normal';" value="Normal">
<input type="button" onClick="document.getElementById('dynamicContent').style.fontStyle = 'italic';" value="Italic">
<input type="button" onClick="document.getElementById('dynamicContent').style.fontFamily = 'courier';" value="Courier">
<input type="button" onClick="document.getElementById('dynamicContent').style.fontFamily = 'roman';" value="Times Roman">
</fieldset>
<p><span id="more-7"></span><br />
Here is the JavaScript code that makes all this possible:<br />
</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;dynamicContent&quot;</span><span style="color: #339933;">&gt;</span>Hello world<span style="color: #339933;">!&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;button&quot;</span> onClick<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;document.getElementById('dynamicContent').style.fontWeight = 'bolder';&quot;</span> value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;Bold&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;button&quot;</span> onClick<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;document.getElementById('dynamicContent').style.fontWeight = 'lighter';&quot;</span> value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;Lighter&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;button&quot;</span> onClick<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;document.getElementById('dynamicContent').style.fontStyle = 'normal';&quot;</span> value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;Normal&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;button&quot;</span> onClick<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;document.getElementById('dynamicContent').style.fontStyle = 'italic';&quot;</span> value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;Italic&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;button&quot;</span> onClick<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;document.getElementById('dynamicContent').style.fontFamily = 'courier';&quot;</span> value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;Courier&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;button&quot;</span> onClick<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;document.getElementById('dynamicContent').style.fontFamily = 'roman';&quot;</span> value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;Times Roman&quot;</span><span style="color: #339933;">&gt;</span></pre></div></div>

<p>
In this example, we use the JavaScript <b>onClick</b> event handler to dynamically change the content styling of the text within the div tags.  To access the div object, we use the <b>getElementById()</b> function and pass over the div id which is, <b>dynamicContent</b> in this case, as the argument.  Once we have access to the div element, we have access to all the styles that are associated with it. </p>
<p>There are a myriad of things that you can change such as font size, font weight, font face, font color, background color, borders and much much more.<br /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.randomsnippets.com/2008/02/24/dynamically-edit-font-styling-of-html-content-via-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
