Jump to content

Select the correct 'alt' attribute from img tag

- - - - -

  • Please log in to reply
2 replies to this topic

#1
Alhazred

Alhazred

    Learning Programmer

  • Members
  • PipPipPip
  • 99 posts
Inside a page I have several downloadable files listed in this way
<div class="crd_downloads_entry_title">
    Koi<br />
    <a href="<?php echo $root ?>downloads/jtemplates/koi/koi-j16template-1.0.zip" >
        <img src="<?php echo $root ?>images/btn_download.png" alt="koi" title="download"/>
    </a>
</div>
I need to write a jquery code which when someone clicks on the download link a php function starts to add one download to that file in the database.
The php function is ready and correct.

This is my jquery code
$(".crd_downloads_entry_title>img").click(function ()
{
    $.ajax({
        url: "<?php echo $root ?>utils/add_download.php?softid="+,
        async: false
    });
});
There something missing in the url, I don't know how to select each time the correct "alt" attribute from the img tag because there are several of those enrtries in my page, all differ only for the alt attribute in the img tag.
The alt attribute is the code of the file which I need to pass to the php script to update the correct entry in the database.

How do I select that attribute accordingly to the user's click?

#2
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
I guess you can do:

$(this).attr("alt"); 

To retrieve the alt attribute of the clicked image.

#3
Alhazred

Alhazred

    Learning Programmer

  • Members
  • PipPipPip
  • 99 posts
Thanks, it works.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users