-1

Before marking as a duplicate, I have looked at the following questions and nothing has worked for me.

jQuery click event requires double click to work

Click and double-click event firing (loosely realted)

I have a JQuery event that requires a single click in some instances and a double click in most others.

Please see the fiddle https://jsfiddle.net/SimonPrice/6e9acbo6/5/

In this fiddle you will see an accurate representation of the data, the expend and collapse functions do not work so I have removed their functions from the javascript window to avoid distraction from popups \ alerts.

In the fiddle you will see a table with a nested table that has nested tables. (Code I have inherited).

Using this code

$(document).ready(function () {

$(document).on('click', '.up', function () {
    shiftRow($(this));
});
$(document).on('click', '.down', function () {
    shiftRow($(this));
});

});

Which is the proposed answer from the first link I cannot get this to work and I am still having to double click.

I have also tried it on the document, table, tr and td elements as well as the class click event it self.

I need this to work on a single click and would be grateful if anyone can help me see the error that I am making.

Simon Price
  • 3,011
  • 3
  • 34
  • 98
  • You're trying to get the expand/collapse buttons to work, correct? – freginold Aug 22 '17 at 14:52
  • 1
    @freginold no, other side of the table, you will see a up and a down arrow... ignore the expand \ collapse buttons. that works fine in the actual application, just not in the fiddle – Simon Price Aug 22 '17 at 14:56

1 Answers1

3

I've added additional log to your function:

function shiftRow(rowbObj) {
console.log("up or down arrow clicked");
var row = $(rowbObj).closest("tr");
console.log(row[0].rowIndex);
var thisTable = row.closest("table");
if ($(rowbObj).is(".up")) {
    if (row[0].rowIndex > 0) {
     console.log("current: "+row.text() + " prev: " +row.prev().text());

So it helped me to realize you have additional hidden TR for the row content (probably for expand) – (

<tr id="content_0_36000" class="content" style="display: none;">

) So when you click once, you replace between the shown and the hidden, that’s why it seems like nothing happens