Yuval200 Posted November 2, 2006 Author Share Posted November 2, 2006 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 More sharing options...
aspnetguy Posted November 2, 2006 Share Posted November 2, 2006 you can't click ona styledo something like this var obj = document.getElementById('theid')obj.onclick = function(){obj.style.color = 'red'} Link to comment Share on other sites More sharing options...
Yuval200 Posted November 2, 2006 Author Share Posted November 2, 2006 you can't click ona styledo something like thisvar 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 More sharing options...
aspnetguy Posted November 2, 2006 Share Posted November 2, 2006 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 More sharing options...
donspeck Posted November 4, 2006 Share Posted November 4, 2006 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 More sharing options...
Chocolate570 Posted November 4, 2006 Share Posted November 4, 2006 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 More sharing options...
donspeck Posted November 4, 2006 Share Posted November 4, 2006 All of the events I've tested in FF, IE, and Opera are case sensitive, always lowercase. How could anything in JS be case insensitive? Link to comment Share on other sites More sharing options...
Yuval200 Posted November 4, 2006 Author Share Posted November 4, 2006 My bad. I just used onClick instead of onclick because of the HTML attribute called like that. Link to comment Share on other sites More sharing options...
donspeck Posted November 4, 2006 Share Posted November 4, 2006 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 More sharing options...
Yuval200 Posted November 4, 2006 Author Share Posted November 4, 2006 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 More sharing options...
Chocolate570 Posted November 5, 2006 Share Posted November 5, 2006 I can definitley make scripts with onClick run. :S Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now