Thursday 15 May 2008

Javascript in a Blogger post

I tried putting in some custom javascript into just a single Blogger post earlier, and simply couldn't understand why I couldn't get it working. It turns out I'd simply forgotten that Blogger, even in 'Edit HTML' mode automagically adds in <br /> tags for line breaks. As such, I ended up with the following when I went to 'view source':

<script language="javascript"> <br />
function toggleLayer( whichLayer ) <br />
{ var elem, vis; <br />
if( document.getElementById ) <br />
// this is the way the standards work <br />
elem = document.getElementById( whichLayer ); <br />
else if( document.all )

... and on. Not the best code I'm sure you'll agree. Hope this help anyone else with the same problem :)

Leave a comment, or read the 3 comments so far.

raje said...

Ya, I know this..

Do u Get Any Solutions.

Ina said...

Yeah...thought I'd made it obvious from my post. Either remove 'automatically add line breaks' (the option's somewhere in blogger), or don't put line breaks in your javascript.

Anonymous said...

Thank for you solution

Recent Tweets