0

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..

Edited by FriXionX: n/a

2
Contributors
2
Replies
4
Views
5 Years
Discussion Span
Last Post by FriXionX
0

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

Edited by Fest3er: n/a

0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.