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


Groups > comp.lang.javascript > #21274

Re: 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 Re: What is the point to use the setAttribute method when there is better way
Date 2013-09-12 02:31 +0200
Organization A noiseless patient Spider
Message-ID <l0r215$176$1@dont-email.me> (permalink)
References <l0pu7u$j9e$1@dont-email.me> <2o2qwle7mok$.1b5nmztiitach$.dlg@40tude.net>

Show all headers | View raw


So in this case it's no point to use setAttributes

//Tony

"JJ" <duh@nah.meh> skrev i meddelandet 
news:2o2qwle7mok$.1b5nmztiitach$.dlg@40tude.net...
> On Wed, 11 Sep 2013 16:20:23 +0200, Tony Johansson wrote:
>> 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
>
> That's because an image element is an HTMLImageElement object, and is 
> based
> on HTMLElement object. So, HTMLImageElement is inherited with all
> HTMLElement object properties.
>
> HTMLElement is inherited with all Element object properties.
> Element is inherited with all Node object properties.
> Node is inherited with all Object object properties. 

Back to comp.lang.javascript | Previous | Next — Previous in thread | 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