Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #21266

What is the point to use the setAttribute method when there is better way

From "Tony Johansson" <johansson.andersson@telia.com>
Newsgroups comp.lang.javascript
Subject What is the point to use the setAttribute method when there is better way
Date 2013-09-11 16:20 +0200
Organization A noiseless patient Spider
Message-ID <l0pu7u$j9e$1@dont-email.me> (permalink)

Show all headers | View raw


Here I have two alternative setImage1 and setImage2 to add a value to the 
scr attribute and the alt attribute for the dieImg object.
I find the second solution setImage2  much easier then the first one.
So my question is if it's any point to use the first solution where you use 
the setAttribute metod
The result from these two function is the same.
function setImage1( dieImg )
         {
             var dieValue = Math.floor(1 + Math.random() * 6);
            dieImg.setAttribute( "src", "img/die" + dieValue + ".png" );

            dieImg.setAttribute( "alt",  "die image with " + dieValue + " 
spot(s)" );
         } // end function setImage

function setImage2( dieImg )
         {
             var dieValue = Math.floor(1 + Math.random() * 6);
             dieImg.src = "img/die" + dieValue + ".png"

            dieImg.alt = "die image with " + dieValue + " spot(s)" );
         } // end function setImage

//Tony 

Back to comp.lang.javascript | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

What is the point to use the setAttribute method when there is better way "Tony Johansson" <johansson.andersson@telia.com> - 2013-09-11 16:20 +0200
  Re: What is the point to use the setAttribute method when there is better way JJ <duh@nah.meh> - 2013-09-12 05:05 +0700
    Re: What is the point to use the setAttribute method when there is better way "Tony Johansson" <johansson.andersson@telia.com> - 2013-09-12 02:31 +0200
      Re: What is the point to use the setAttribute method when there is better way Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-09-12 11:34 +0200

csiph-web