Note that there are some explanatory texts on larger screens.

plurals
  1. POcatch programmatically triggered event with jquery
    primarykey
    data
    text
    <p>I have an input element which has a keypress event handler attached:</p> <pre><code>// ASSIGN ENTER KEYPRESS TO PAGE SELECTOR $(document).on('keypress', '.list-ui-page-selector', turnPage); </code></pre> <p>The user enters a number into the input and presses the ENTER key. The turnPage() function checks what the pressed key was. If it was ENTER, then starts an ajax request:</p> <pre><code>function turnPage(event){ if(event.which != 13) return; var page = $(this).val(); var unique = $(this).attr('id').replace(/[^\d.]/g,''); animateTableUpdating(unique); ajaxRequest(unique, null, null, page); }// turnPage </code></pre> <p>This works properly, but I'd like some buttons which can increment and decrement the number value in the input field. When I increased or decreased the value I trigger an ENTER keypress event:</p> <pre><code>// PAGE SCROLLING BUTTONS $(document).on('click', ".list-ui-next-page", function(){ var unique = $(this).attr('id').match(/\d{8}/gi); var page = parseInt($("#list-ui-page-selector\\["+unique+"\\]").val()); var page_total = parseInt($("#list-ui-page-total\\["+unique+"\\]").val()); if(page &lt; page_total){ page++; $("#list-ui-page-selector\\["+unique+"\\]").val(page); var e = jQuery.Event("keydown"); e.which = 13; e.keyCode = 13; $("#list-ui-page-selector\\["+unique+"\\]").trigger(e); } }); </code></pre> <p>The problem is that the programically triggered event is not handled by $(document).on('keypress', '.list-ui-page-selector', turnPage); and turnPage is not invoked. How could I catch these events too?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload