Results 1 to 3 of 3

Thread: get & set attribute functions

  1. #1
    Join Date
    May 2007
    Location
    USA
    Posts
    373
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Default get & set attribute functions

    Is there much of a point to using something like:

    img.setAttribute("src", "www.mysite.bmp");

    vs.

    img.src = "www.mysite.bmp";

    If there is, why? Is it for private data (if JS has that stuff)? And the samething for getAttribute.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I'd assume that this is useful when the attribute isn't availabe in the object.attribute method.
    This might work for a made up attribute, perhaps, if you needed to store an additional property in the tag. I'm not really sure.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Trinithis View Post
    Is there much of a point to using something like:

    img.setAttribute("src", "www.mysite.bmp");

    vs.

    img.src = "www.mysite.bmp";
    Not usually, no.

    Keep in mind that the DOM isn't just for the Web, nor is it only for HTML. The DOM can also be used for manipulating XML documents and the short cut property accessors are not defined in this case; using the set/getAttribute methods is the only choice.

    When scripting browsers, avoid the method approach. MSIE doesn't implement them properly.
    Mike

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •