Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery replacement for onclick

I've just recently discovered the power of jQuery. Just a quick question though.

What is a replacement for onclick="DeleteSomething('THE ID NUMBER LOADED IN BY SERVER SIDE')" ?

Is there even a way somehow to pass custom information such as an ID to a jQuery onclick? Or do I have to stay with the old fashioned way?

like image 460
Adam Avatar asked May 10 '26 17:05

Adam


2 Answers

I usually use a rel="" for some extra data i might need attached to the button or whatnot.

for example

<input class="btnDelete" rel="34" value="Delete" />

then in jquery

$('.btnDelete').click(function() {
    DeleteMethod($(this).attr("rel"));
  });
like image 113
John Boker Avatar answered May 12 '26 07:05

John Boker


If you stick the ID of the object you want to delete in the rel parameter, you can do it this way:

<script type="text/javascript>

$('a.deleter').click(function(){
   if($(this).attr("rel") != ""){
      DeleteSomething($(this).attr("rel"));
   }
});

</script>
<a href="javascript:void(0)" rel="54" class="deleter">Delete Widget</a>
like image 25
Iain Fraser Avatar answered May 12 '26 06:05

Iain Fraser



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!