I have a code and on page load it gets clicked, I see by alert for example. The problem is it send not needed ajax request. Its hard to find origin clicker by hand. Is there a way programically detetc who clicked the class?

//Delete all event from betting slip
    $('.clear_all_slip').click(function() {

        alert('who click?');


        $.getJSON(base_url_lang + "ajax/clear_slip/", function(data){

            if (data.length == 0) {


                $('#stake_per_bet').attr('value', '');
                $('#stake_express').attr('value', '');

5 Years
Discussion Span
Last Post by McLaren

Use "this"

this - refers to the element who clicked it
or you may use the event obj.

e.g. (this)

console.log('element who clicked', this);

e.g. (event)

$('.clear_all_slip').click(function(event) {
  console.log('target', event.target);

thanks, I will try with this and even.target.

Look for click() anywhere in your code.
I did, but it took much more time, because even when seach function found it, I did not notice right away - it was hidden between search results :)


I tested, but there is a problem. I see the element WHICH was clicked, but not WHO clicked. I mean when not human clicks. I am having another problem - using barcode scanner - it clicks for some reason the link, and I don't get from where it clicks.
Like in PHP there is function stack or somethign like that.


There is a return as one of the characters, so it will click the default submit button (at least that's my guess). Had something similar happen before with a mag reader.


As far as I know, barcode scanner work as a keyboard. So it may be sending an Enter key that click the default submit button, as said by stbuchok.

I'd suggest you to remove any <button type="submit" /> and <button /> and try it again.
Ps.: Buttons without types are treated as submit type too.


yeah, I find out that it sends #13 key, and made a workaroud - when script detects it, I do apropriate actions. But still for me does not make sence why the link is clicked. I mean enter key with keyboard does not click the link. And when I detected that 13 key and made it not react, the problem gone. Just would be interesting to know why it could happen. For better understanding I show the workaroudn code part:

else {  //focus on nothing - try to read/scan barcode

            if (e.which >= 48 && e.which <= 57) {    //if number

                current_barcode += String(e.which-48);

                if (current_barcode.length == 10) {

                    //there is hidden barcode input for all shop pages, so this is submited

                    if (current_method != 'main') {
                        $('#hidden_check_barcode [name=check_submit]').click(); // the page here is redirected
                    else {

                        // scanned_barcode - from redirection
                        // current_barcode - in this file variable
                        if (scanned_barcode.length != 10 && current_barcode.length != 10) {
                            reset_payout_page('reset_fields');  // for barcode scan its bad to reset
                        else {
                            // barcode posted from other page - so check it
                            scanned_barcode = ''; // reset so next time when opening page barcode would not be filled in and checked


            } else {

                if (current_barcode.length == 10 && e.which == 13) {
                    // otherwise it catches #13 key (last barcode char probably)
                    // which is not needed and cause problems - for unknown reason link of the game gets clicked

                //if something else pressed, reset
                current_barcode = '';



It's an <a> or an <button>?

link which should not be clicked on snanning is <a>, or I did not understand the question

Edited by McLaren

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.