Jump to content

Problem with the getElementsByTagName method.


Yuval200

Recommended Posts

So the problem is that the code executes one more time, and in that last time, it cannot find other tags, so it dies? I see, thanks guys, it works now :)One last question- I haven't managed to do a styling thing in JS with a combinated event. I tryed something like:

document.body.style.color.onClick = 'red';

But it doesn't work.. Do you have any ideas?

Link to comment
Share on other sites

you can't click ona styledo something like this
var obj = document.getElementById('theid')obj.onclick = function(){obj.style.color = 'red'}

Thanks man, you (and others here) helped me alot :)Interesting.. I never knew that functions don't have to have names..
Link to comment
Share on other sites

just note that defining the functionthe way I did means you cannot reference it later on...only use that way if you only need the function once.Else do it this way

var obj = document.getElementById('theid')obj.onclick = changeColorfunction changeColor(){  obj.style.color = 'red'}

Link to comment
Share on other sites

One last question- I haven't managed to do a styling thing in JS with a combinated event. I tryed something like:
document.body.style.color.onClick = 'red';

But it doesn't work.. Do you have any ideas?

Even if there were a color object and it had an onclick event handler this code would not work because the C is capital. What would happen is the color object would be dynamically assigned an onClick method.Sorry Guys, I know, like a pit bull, but I suspect people are having trouble with this but they just don't know what the ###### is happening.
Link to comment
Share on other sites

You're right, but it would still probably work. It depends on what browser you're using--most of the events are case insensitive.But because of the 'most', it's a good idea to follow skimmy's instructions.

Link to comment
Share on other sites

Yes, I had that problem too. Many examples in html use uppercase letters wherever they want. It works because html is not case sensative, although valid xhtml is always all lowercase (or is that just tags?). JS however is case sensative so when you use the same name you got used to in html it doesn't work. It doesn't generate an error, it does something totally different.

Link to comment
Share on other sites

Yes, I had that problem too. Many examples in html use uppercase letters wherever they want. It works because html is not case sensative, although valid xhtml is always all lowercase. JS however is case sensative so when you use the same name you got used to in html it doesn't work. It doesn't generate an error, it does something totally different.
Yes, I use XHTML T too.And I know Javascript is key-sensitive, I fought those events are uppercase (like onClick) because of normal HTML.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...