DOM + Setting Style

  • Digg this article
  • Sphinn this article
  • Stumble this article
  • Facebook
  • del.icio.us
  • LinkedIn
  • Twit this article
Posted by John
on Monday, 07 January 2008

Quick little article for those hacking AJAX.

One of the powers of JavaScript is it's ability to let you change the property of elements within your webpage on-the-fly (the cornerstone of ajax).

So say you've got an element in your html like;

<span id="elem">some text</span>

Now if i wanted to make it strikethru in JavaScript I'd do...

<script type="text/javascript">
document.getElementById("elem").style.textDecoration="line-through";
</script>

Cool eh, your basically telling the DOM to hunt down any html element with the ID of 'elem' and then change it's CSS text style programatically.

NOTE: style is lowercase, not uppercase!