Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Jun 2006
    Posts
    70
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Add "ALT" attribute to javascript

    Hi there, can anyone let me know how to add an "ALT" tag to this bit of javascript?

    myimages[1]="html/images/cat-image-10.jpg"

    Cheers

  • #2
    Regular Coder ninnypants's Avatar
    Join Date
    Apr 2008
    Location
    Utah
    Posts
    504
    Thanks
    10
    Thanked 47 Times in 47 Posts
    This will do it
    Code:
    myimages[1].alt = "this is alt text";

  • Users who have thanked ninnypants for this post:

    malhyp (08-29-2008)

  • #3
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    Code:
    myimages[1].setAttribute('alt','whatever');
    If nothing worsk, show us the rest of the script.
    Edit:
    Sorry ninnypants.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • Users who have thanked rangana for this post:

    malhyp (08-29-2008)

  • #4
    New Coder
    Join Date
    Jun 2006
    Posts
    70
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Ok, do I combine it in one line or two?

    E.g. myimages[1]="html/images/cat-image-10.jpg", "setAttribute('alt','whatever')";

    or like this

    myimages[1]="html/images/cat-image-10.jpg",
    myimages[1].setAttribute('alt','Cat Image 10');
    myimages[2]="html/images/cat-image-11.jpg",
    myimages[2].setAttribute('alt','Cat Image 11');

    Cheers

  • #5
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    The later should work, except you need to replace the comma ( , ) with colon ( ; ):
    Code:
    myimages[1]="html/images/cat-image-10.jpg";
    myimages[1].setAttribute('alt','Cat Image 10');
    myimages[2]="html/images/cat-image-11.jpg"; 
    myimages[2].setAttribute('alt','Cat Image 11');
    If nothing helps, up a link or show to us the rest of the script.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • Users who have thanked rangana for this post:

    malhyp (08-29-2008)

  • #6
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,853
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    myimages[1]="html/images/cat-image-10.jpg",
    If you are assigning the src attribute, the above should be
    Code:
    myimages[1].src="html/images/cat-image-10.jpg";
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    malhyp (08-29-2008)

  • #7
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm having the same trouble with adding an ALT tag to the last image:

    var imageList = [
    "images/banner/banner1.jpg",
    "images/banner/banner2.jpg",
    "images/banner/banner3.jpg",
    "images/banner/banner4.jpg",
    "images/banner/banner4.jpg",
    ];

    Can anyone help?

  • #8
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,982
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    "images/banner/banner4.jpg",
    "images/banner/banner4.jpg",

    banner5.jpg???

    But please do not hijack ancient and long-resolved threads - prefer to start a new thread of your own with an appropriate and helpful title.

    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

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