trying to get an attribute value

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike

    trying to get an attribute value

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

    Thanks
    Mike
  • Stevo

    #2
    Re: trying to get an attribute value

    Mike wrote:
    Hello,
    I'm trying the following code:
    function MoveTeam(id){
    This works-gets the value of the element
    var x=document.getE lementById(id). innerHTML;
    This doesnt get the value of the alpha attribute of the same element.
    I get a js error.
    var q=document.getE lementByID(id). attribute('alph a')
    alert (q)
    Thanks
    Mike
    You've upper-cased the ID in getElementById.

    Comment

    • SAM

      #3
      Re: trying to get an attribute value

      Mike a écrit :
      Hello,
      I'm trying the following code:
      function MoveTeam(id){
      This works-gets the value of the element
      var x=document.getE lementById(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.getE lementByID(id). attribute('alph a')
      if(document.get ElementsByTagNa me("body")[0] &&
      document.getEle mentsByTagName( "body")[0].hasAttribute &&
      document.getEle mentsByTagName( "body")[0].hasAttribute(' style') )
      alert(document. getElementsByTa gName("body")[0].getAttribute(' style'));

      <http://developer.mozil la.org/en/docs/DOM:element.get Attribute>

      --
      sm

      Comment

      • Dr J R Stockton

        #4
        Re: trying to get an attribute value

        In comp.lang.javas cript message <4829befe$0$866 $ba4acef3@news. orange.fr>
        , Tue, 13 May 2008 18:17:01, SAM <stephanemoriau x.NoAdmin@wanad oo.fr.inv
        alidposted:
        >
        >if(document.ge tElementsByTagN ame("body")[0] &&
        document.getEle mentsByTagName( "body")[0].hasAttribute &&
        document.getEle mentsByTagName( "body")[0].hasAttribute(' style') )
        >alert(document .getElementsByT agName("body")[0].getAttribute(' style'));
        I think the following might work more efficiently :-

        if ( (T=document.get ElementsByTagNa me("body")[0]) &&
        (T=TT.hasAttrib ute) && (T=T('style')) ) alert(T);
        // ^ ?

        Certainly there should be no need to repeat
        document.getEle mentsByTagName( "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.demo n.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)

        Comment

        Working...