![]() |
Get this element ! :(
I have the following javascript in a page
:
function chgsubmnu(mnuname){which is supposed to affect the background of this td when the mouse is on it.. :
<td name="menu2" id="b2" onmouseover="chgsubmnu('menu2')" onmouseout="resmenu('menu2')">Content</td>IE returns an error stating the document.getElementsByName(...).style.bgColor is null or not an object? I am confused....what wrong :-? |
IE does not support getElementsByName () for every type of element. I'm not predisposed to Google and find an appropriate list, but I assure you, you can.
|
Try using document.getElementById instead. That is considered the correct way of doing things if you need to access only one element, which seems to be the case, looking at your code.
|
Quote:
rather than a single object reference. That is where the OP has gone wrong. You need to use an index to tell it which element in the array you are pointing to. In this case: :
document.getElementsByName(mnuname)[0].style.bgColor = '#35A695';Having said that, it would be much simpler to do something like this: :
<td name="menu2" id="b2" onmouseover="chgsubmnu(this)" onmouseout="resmenu(this)">Content</td>:
function chgsubmnu(mnuname){ |
I'm guilty of quoting a site without actually double-checking it, Agent. They published a list. It's been a while, maybe a year, but I'll see if I can find it.
|
Quote:
Just one small question...what does 'this' return? 1) in terms of string only the value of id? or 2) document.getElementById('value') |
'this' doesn't return anything, it is simply a direct reference to an
element in the page. The equivalent using getElementById() would be: :
onmouseover="chgsubmnu('b2')":
function chgsubmnu(mnuname){ |
I'm resurrecting this thread because "document.getElementsByName" isn't working for me in the case of divs, in the case of IE. Viewing the source shows the collection of divs all having the same name (their ids are different). The value returned is shown by IE to be an object, but its length is zero. Mozilla, et.al., show the correct length (which varies according to a particular person's number of sales). Agent?
|
According to this site:
Quote:
The standard Javascript library is lacking a getElementsByClassName function, but a quick search on Google will throw up a large number of custom functions with that name. I use the one from the lightweight prototype.lite library. |
Thanks, Arevos. I actually read the page you reference this morning, but I like to double-check. I guess I was hoping someone would say, "Well, did you do blah blah?" and point out a simple possible oversight on my part. I'm fresh out of dead chickens, so I suppose the voodoo ainnagonnawoik.
EDIT: FEEDBACK. Wrote my own, woiks like a champ :D . |
| All times are GMT -5. The time now is 5:10 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC