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 12 of 12
  1. #1
    New Coder
    Join Date
    Aug 2008
    Location
    Brooklyn
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Unhappy Alt Attribute in Image Array

    I would like to add an "Alt Attribute" to each image.
    All images on the page apper in the same spot (like a gallery) so one replaces the other;
    using the function:


    function rightImage(theImage){

    if(imageNum>19){
    imageNum=-1}

    theImage.src=myImage[imageNum+1];
    imageNum++


    }

    I tried adding alt to the array:

    myImage= new Array(20)

    myImage[0]="images/copyRight_f001.jpg"
    myimage[0].setAttribute('alt','tuna with mango');
    myImage[1]="images/copyRight_f002.jpg"
    myimage[1].setAttribute('alt','scallop ceviche');
    ...
    but then page gives an error



    the page and source can be viewed at www.sashagitin.com/food
    Thank you very much for your help.
    Last edited by infisoul; 08-29-2008 at 04:31 PM.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,859
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    myImage[0]="images/copyRight_f001.jpg"
    myimage[0].setAttribute('alt','tuna with mango');
    myImage[1]="images/copyRight_f002.jpg"
    myimage[1].setAttribute('alt','scallop ceviche');
    Neither the above code nor the error specified is visible to me in the page given above.
    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:

    infisoul (08-29-2008)

  • #3
    New Coder
    Join Date
    Aug 2008
    Location
    Brooklyn
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question

    sorry here is the page with error:
    http://sashagitin.com/beta/food/indexTest.html

    it's a bit confusing. Because it interacts with another function that plays the gif animation while image is loading.

    so when array doesn't include "alt" it workes fine
    myImage[0]="images/copyRight_f001.jpg"

    but with alt
    myimage[0].setAttribute('alt','tuna with mango');

    it doesn't display the image and freezes at gif animation

    thanks

  • #4
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    JS is case-sensitive. myimage is different from myImage.

    Hope that makes sense.
    Learn how to javascript at 02geek

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

  • #5
    New Coder
    Join Date
    Aug 2008
    Location
    Brooklyn
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question

    Thank you rangana for noticing the case... i changed it but.... it still doesn't work....

    Would anyone have a sample of the whole page where alt attribute in the image is assigned by Javascript?
    Million Thanks.

  • #6
    New Coder
    Join Date
    Aug 2008
    Location
    Brooklyn
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Also I have a SEO question on the same topic. Does google or other engines read Alt text assigned to the image in javascript ???

  • #7
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    Have you updated your page already? It seemed that I (still) see the typo:
    Code:
    myimage[0].setAttribute('alt','tuna with mango');
    myImage[1]="images/copyRight_f002.jpg"
    myimage[1].setAttribute('alt','scallop ceviche');
    Change highlighted to myImage.
    Learn how to javascript at 02geek

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

  • #8
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by infisoul View Post
    Thank you rangana for noticing the case... i changed it but.... it still doesn't work....

    Would anyone have a sample of the whole page where alt attribute in the image is assigned by Javascript?
    Million Thanks.
    you have few errors in javascript:
    Code:
    myImage[0]="images/copyRight_f001.jpg"
    myimage[0].setAttribute('alt','tuna with mango');
    myImage[1]="images/copyRight_f002.jpg"
    myimage[1].setAttribute('alt','scallop ceviche');
    imageNum = 19; must be in code before first place where you use it, more exactly all declaration including myImage.

    your first concern about seo must be in layout, you use a 5 depth table, hard to read by google bot.

    best regards
    Last edited by oesxyl; 08-31-2008 at 06:38 AM.

  • #9
    New Coder
    Join Date
    Aug 2008
    Location
    Brooklyn
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts

    different solution

    setAttribute('alt','text');
    Simply didn't work ( and i did change case)

    however what worked was a separate array
    imageNum=0


    myAlt= new Array(20)

    myAlt[0]="tuna1"
    myAlt[1]="scallop2"
    myAlt[2]="tuna3"
    myAlt[3]="shrooms"
    myAlt[4]="tofu"
    myAlt[5]="radish"

    and just one more line added to the function
    theImage.src=myImage[imageNum+1];
    theImage.alt=myAlt[imageNum+1];

    sample can be seen in source http://www.sashagitin.com/beta/food/codeTest.html

    alt text changes on main image when arrow is used.

    However after testing in with Linxs and other SEO tools it turned out that Alt Text in Javascript is OBSOLUTELY USELESS. Google bot simply doesn't see it.

  • #10
    New Coder
    Join Date
    Aug 2008
    Location
    Brooklyn
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts
    oesxyl : you wrote: your first concern about seo must be in layout, you use a 5 depth table, hard to read by google bot.
    Any source that is not 10 years old suggests that google bot has no problem with nested tables. PLEASE prove sopportive evedance. is you know otherwise

    My problem is that the whole website is only visual and any actual text will desturb prospects from viewing the images. In the eyes of google the site is almost empty. Thats why i am trying to create alt text. However creating alt text in javascript did not help. ...

  • #11
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by infisoul View Post
    oesxyl : you wrote: your first concern about seo must be in layout, you use a 5 depth table, hard to read by google bot.
    Any source that is not 10 years old suggests that google bot has no problem with nested tables. PLEASE prove sopportive evedance. is you know otherwise
    prove me that this is more readable:
    Code:
    <table>
      <tr>
        <td>
           <table>
              <tr>
                 <td>
                   <table>
                      <tr>
                        <td>
                          <table>
                             <tr>
                               <td>
                                  <table>
                                     <tr>
                                        <td>
                                           <img ....
    then this:
    Code:
    <div>
       <img.....
    there are a lot of arguments seo and non-seo against this.

    My problem is that the whole website is only visual and any actual text will desturb prospects from viewing the images. In the eyes of google the site is almost empty. Thats why i am trying to create alt text. However creating alt text in javascript did not help. ...
    is visual because your thinking is visual, , google have google image bot and you can make your gallery more bot friendly and overall is a matter of proper design.

    Code:
    <div id="p1" class="dh">
       <img src="p1.jpg" alt="p1 alt" title="p1 title" />
    </div>
    <div id="p2" class="dh">
       <img src="p2.jpg" alt="p1 alt" title="p1 title" />
    </div>
    Code:
    .dh { display: none; }
    and then you can use javascript to make #p1 display: block when the page is loading and as far as the user click of one of the buttons to navigate, you change none to block and block to none to display each image.

    best regards

  • #12
    Regular Coder Samhain13's Avatar
    Join Date
    Aug 2008
    Location
    Pilipinas
    Posts
    169
    Thanks
    4
    Thanked 18 Times in 18 Posts
    If I may butt in...

    The alternate text attribute is not meant for SEO anyway, it's there for accessibility reasons-- although SEO and accessibility are not mutually exclusive. But considering that robots' reading of alt text is already a bit iffy, it's a lot less likely that javascript-generated alt text will be of help where SEO is concerned.

    +1 on oesxyl's hidden content solution. Cheers!
    Last edited by Samhain13; 09-03-2008 at 01:54 AM.


  •  

    Posting Permissions

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