trying to get an attribute value

M

Mike

Hello,
I'm trying the following code:
function MoveTeam(id){
This works-gets the value of the element
var x=document.getElementById(id).innerHTML;
This doesnt get the value of the alpha attribute of the same element.
I get a js error.
var q=document.getElementByID(id).attribute('alpha')
alert (q)

Thanks
Mike
 
S

Stevo

Mike said:
Hello,
I'm trying the following code:
function MoveTeam(id){
This works-gets the value of the element
var x=document.getElementById(id).innerHTML;
This doesnt get the value of the alpha attribute of the same element.
I get a js error.
var q=document.getElementByID(id).attribute('alpha')
alert (q)
Thanks
Mike

You've upper-cased the ID in getElementById.
 
S

SAM

Mike a écrit :
Hello,
I'm trying the following code:
function MoveTeam(id){
This works-gets the value of the element
var x=document.getElementById(id).innerHTML;
This doesnt get the value of the alpha attribute of the same element.

what is an alpha attribute ?
I know style (style="filter:alpha(50)")

but ... alpha as attribute of a div ... no I doesn't know.

I get a js error.
var q=document.getElementByID(id).attribute('alpha')

if(document.getElementsByTagName("body")[0] &&
document.getElementsByTagName("body")[0].hasAttribute &&
document.getElementsByTagName("body")[0].hasAttribute('style') )
alert(document.getElementsByTagName("body")[0].getAttribute('style'));

<http://developer.mozilla.org/en/docs/DOM:element.getAttribute>
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]>
, Tue, 13 May 2008 18:17:01, SAM <[email protected]
alid> posted:
if(document.getElementsByTagName("body")[0] &&
document.getElementsByTagName("body")[0].hasAttribute &&
document.getElementsByTagName("body")[0].hasAttribute('style') )
alert(document.getElementsByTagName("body")[0].getAttribute('style'));

I think the following might work more efficiently :-

if ( (T=document.getElementsByTagName("body")[0]) &&
(T=TT.hasAttribute) && (T=T('style')) ) alert(T);
// ^ ?

Certainly there should be no need to repeat
document.getElementsByTagName("body")[0].hasAttribute('style')
except for those paid for code by the yard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,141
Messages
2,570,818
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top