"Uncaught Syntaxerror: Missing ) after argument list" in . append Jquery

Asked

Viewed 415 times

0

I am receiving "Uncaught Syntaxerror: Missing ) after argument list" which accuses the line of the last closed parenthesis, that inside the callback of a jquery post. I tried to close every possible way, and even then I get the error. I do not understand how these parentheses have to be closed.

$("#exchangers tbody").append(
    $("<tr class='tr_row' id='tr_" + elPosition + "'>").css({cursor:'pointer'}).append(
        $("<td id='td_" + elPosition + "'>").append($("<i id='io" + elPosition + "' onmousedown='shc(" + elPosition + ")' onclick='stopBubbling(event)' onmouseover=\"show_info(" + elPosition + ", '" + el.nome + "', '" + el.https + "', '" + el.moeda_from + "', '" + el.moeda_to + "', '" + el.idade + "', '" + el.url_redirect + "', '" + el.wmid + "', '" + el.pais_nome + "', '" + el.rank_from + "', '" + el.rank_to + "', '" + el.amount + "')\" onmouseout='shd(" + elPosition + ")'>").addClass('fa fa-info-circle io').html("")),
        $("<td>").html('<a class="a_row" href="' + URL_SITE + '/click/' + el.exchange_rates + '.html" target="_blank">' + el.nome + '</a>'),
        $("<td>").html(el.in + " " + el.from),
        $("<td>").html(el.out + " " + el.to),
        $("<td>").html(el.amount + " " + el.to),
        $("<td class='a_comment text-center'>").append(
            '<a class="a_row" style="width: 90px !important;" href="' + URL_SITE + '/exchangers/' + el.link_permanente + '.html">',
            $('<span>').append(
                $('<span>').addClass('text-danger').html(parseInt(el.reviews[0]["negativo"])),
                "/",
                $('<span>').addClass('text-success').html(parseInt(el.reviews[0]["positivo"]) + parseInt(el.reviews[0]["comentario"]) + parseInt(el.reviews[0]["negativo"])),
            ),
            '</a>'
        )
    );

Commenting on the code in parts, I realized that the error comes from here:

$("<tr class='tr_row' id='tr_" + elPosition + "'>").css({cursor:'pointer'}).append(
     $("<td id='td_" + elPosition + "'>").append($("<i id='io" + elPosition + "' onmousedown='shc(" + elPosition + ")' onclick='stopBubbling(event)' onmouseover=\"show_info(" + elPosition + ", '" + el.nome + "', '" + el.https + "', '" + el.moeda_from + "', '" + el.moeda_to + "', '" + el.idade + "', '" + el.url_redirect + "', '" + el.wmid + "', '" + el.pais_nome + "', '" + el.rank_from + "', '" + el.rank_to + "', '" + el.amount + "')\" onmouseout='shd(" + elPosition + ")'>").addClass('fa fa-info-circle io').html(""))

I’m forgetting to miss something?

  • You see, your initial question had an error that was pointed out in the answer... by changing your answer now without the error, it will render the answer invalid. It’s okay that the problem may not be exactly just the case in the parentheses, but don’t change the question by disabling answers given. What you should do is edit the question and add new information.

  • I removed the answer in order to understand better. The code seems to be correct, but it is still giving error?

  • It seems to be something with the quotation marks, in some places you use double quote pro Javascript and single quote pro dynamic html, then you do the opposite elsewhere. Try to follow a unique pattern, too as I remember it. Type this: onclick='stopBubbling(event)' onmouseover=\"show_info(" + elPosition In onclick you used single quote and onmouseover double quote with backslash to work, but at some point you wrote so that you confused javascript.

  • What it seems to me is that some text in the variables is coming with quotes and is "breaking" the code.

1 answer

1


Perdugames What I did in your code:

  • I added a parenthesis at the end before ';' to close the first jquery append function;
  • I changed the double quotes " in the onmouseover call to quote ' (or single quote);
  • I pulled an extra comma in the last append.

Executed normally here.

var elPosition = 1;
var URL_SITE = 'http:www.com';

var el = {
  nome: 'Cleyton',  https: 'Sim', moeda_from: 'USD', moeda_to: 'BRL', idade: 100, url_redirect: 'Pagamento', wmid: 1, pais_nome: 'For for way', rank_from: 1, rank_to: 2, amount: 1.00, in: 'entrada', out: 'saida', from: 'Joaquim', to: 'Pedro', reviews:[{negativo: 2,positivo: 5,comentario: 2}]
};



$("#exchangers tbody").append(
    $("<tr class='tr_row' id='tr_" + elPosition + "'>")
        .css({cursor:'pointer'})
        .append(
            $("<td id='td_" + elPosition + "'>")
                .append(
                    $("<i id='io" + elPosition + "' onmousedown='shc(" + elPosition + ")' onclick='stopBubbling(event)' onmouseover='show_info(" + elPosition + ", '" + el.nome + "', '" + el.https + "', '" + el.moeda_from + "', '" + el.moeda_to + "', '" + el.idade + "', '" + el.url_redirect + "', '" + el.wmid + "', '" + el.pais_nome + "', '" + el.rank_from + "', '" + el.rank_to + "', '" + el.amount + "') onmouseout='shd(" + elPosition + ")'>")
                    .addClass('fa fa-info-circle io')
                    .html("")
                ),
            $("<td>").html('<a class="a_row" href="' + URL_SITE + '/click/' + el.exchange_rates + '.html" target="_blank">' + el.nome + '</a>'),
            $("<td>").html(el.in + " " + el.from),
            $("<td>").html(el.out + " " + el.to),
            $("<td>").html(el.amount + " " + el.to),
            $("<td class='a_comment text-center'>").append(
                '<a class="a_row" style="width: 90px !important;" href="' + URL_SITE + '/exchangers/' + el.link_permanente + '.html">',
                $('<span>').append(
                    $('<span>').addClass('text-danger').html(parseInt(el.reviews[0]["negativo"])),
                    "/",
                    $('<span>').addClass('text-success').html(parseInt(el.reviews[0]["positivo"]) + parseInt(el.reviews[0]["comentario"]) + parseInt(el.reviews[0]["negativo"]))
                ),
                '</a>'
            )
        )
    );
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
  <table id='exchangers'>
    <tbody>
    </tbody>
  </table>
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>

</body>
</html>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.