I'm completely new to javascript, but in my eyes this should work.
But then again, i'm quite an idiot myself and it's usually a very very simple problem that someone will see in 5 seconds. I want the header (supposed to be in variable 'itemname') to be put into variable item1, then the alertbox to come up with the string that was inserted into the variable.
Say if the header had the word 'Hello' in it, then when you click a button, 'Hello' would come up in an alert. And if the header had the word 'Goodbye', then the alert would say 'Goodbye'.

<script type="text/javascript">
function alert() {
var item1 = document.getElementById("itemname");
alert(item1);
}
</script>

(next snippet is the html)

<h1 id=”itemname”>
Hello
</h1>

Shouldn't this work? All it does is show 'null'.
Thanks for the help.


edit: lol, i was right. figured it out about 20 minutes after this thread. just remade the code exactly the same way and it worked. no clue what happened, but yeah. solved..

Shouldn't your function recurse infinitely (at least until memory is exhausted)?

Shouldn't your function recurse infinitely (at least until memory is exhausted)?

Oh woops, I forgot to include the button onclick thing in that post. Told ya I was dumb aha.

Don't worry, I fixed it some time ago, but thanks for looking out for that.