I'm not sure if its the best way of doing this, but I have a few images on my page, and want each of them to have a different action. The one below adds a record to a database when clicked, if I want to add another image to click to delete, how do I make it unique so my .click
function can launch a delete.php file? (data is hard coded at the moment as you can see)
<a href=""><img src="/wp-content/themes/Atlantis/images/add.gif" /></a>
<script type="text/javascript">
$(document).ready(function() {
$("a").click(function() {
$.ajax({
url: 'add.php',
data: "Masterselect=11&UserID=55&Status=W",
dataType: 'json',
});
alert("Thanks for adding");
});
});
</script>
I would name your links -- give them a class or id attribute
<a class="add" href=""><img src="/wp-content/themes/Atlantis/images/add.gif" /></a>
<a class="delete" href=""><img src="/wp-content/themes/Atlantis/images/delete.gif" /></a>
And then you could specify one function for the add button, another for the delete, and so on:
$("a.add").click(...);
$("a.delete").click(...);