Connecting Tech Pros Worldwide Forums | Help | Site Map

trying to get an attribute value

Mike
Guest
 
Posts: n/a
#1: Jun 27 '08
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

Stevo
Guest
 
Posts: n/a
#2: Jun 27 '08

re: trying to get an attribute value


Mike wrote:
Quote:
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.
SAM
Guest
 
Posts: n/a
#3: Jun 27 '08

re: trying to get an attribute value


Mike a écrit :
Quote:
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.

Quote:
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>

--
sm
Dr J R Stockton
Guest
 
Posts: n/a
#4: Jun 27 '08

re: trying to get an attribute value


In comp.lang.javascript message <4829befe$0$866$ba4acef3@news.orange.fr>
, Tue, 13 May 2008 18:17:01, SAM <stephanemoriaux.NoAdmin@wanadoo.fr.inv
alidposted:
Quote:
>
>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.

--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/- FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "" (SonOfRFC1036)
Closed Thread