my code is working in jsfiddle but not in the browser.
How are you viewing the jsfiddle website, if not with a browser?
But seriously: how does your markup+code differ from that which you put in jsfiddle? Is jsfiddle loading any assets for you (e.g., jQuery)? is jsfiddle running your code on DOM ready, and did you make sure to do the same?
Also, I know the formatting is bad here on the forums, but it looks like the code you posted is missing an opening bracket (right after
else), and a semicolon (right after