Can you click on a <TD> and get the value of another <TD> Hide?

Asked

Viewed 755 times

0

One with 4 , being an Hide. Is there any way I can click on any and take the value of this Hide and send it to my controller? That way I get the value of the is being clicked.

$('#nmUsuario').on("dblclick", '.clique', function () {
    CarregaDados($(this).text());
})

function CarregaDados(ajaxParameter) {

    $.ajax({

        url: '/CadastroAcesso/CarregaDadosPagina',
        datatype: 'json',
        contentType: 'application/json;charset=utf-8',
        type: 'POST',
        data: JSON.stringify({ _nivel: ajaxParameter }),
        success: function (data) {
        },
        error: function (error) {
        }
    })
}

Now, how do I click on this <TD> and take the value of what is Hide. I think I should take hi value from <TR>, make a each and load only the value of the <TD> But I’m getting caught up in it. How to go through the <TR> to catch the <TD> that I want.

I’ve been away for a while and now I’ve come back to finish what I started. Keep giving error. It does not enter the success of ajax, on the contrary, it enters the function Error of ajax.

  • Maybe you can only do it by going to pick up td by id or name

3 answers

0


I resolved so:

$(this).parent().find(".idusuario").text()

0

Use the :not(:Visible selector)

var conteudoHtmlTd = $("td:not(:visible)").html(); //se quiser o html da td
var conteudoTextoTd = $("td:not(:visible)").text(); //se quiser so o texto da td

If you want to catch a tdHide that is on the same line as another td that you clicked would look like this:

$(document).on("click", "td", function(){
    var conteudoHtmlTd = $(this).parent().find("td:not(:visible)").html();
});

If she has a class, it’s even easier:

$(document).on("click", "td", function(){
    var conteudoHtmlTd = $(this).parent().find(".classe").html();
});

0

Let’s say your hidden TD has a name:

<td class="escondida" style="display:none;">Valor escondido</td>

Then just change your code to:

$('#nmUsuario').on("dblclick", '.clique', function () {
    CarregaDados($(this).find(".escondida").text());
});

I haven’t tried it in jfiddle but if it doesn’t work out take a look at the jquery find command, it will solve it for you.

  • It is coming empty. The tbody of the table is mounted dynamically via jquery. Does this not affect?

  • If the script call is happening before the creation then it would affect it. Could you add a fiddle of your code or put it there in your question to see if we can walk more in the solution?

  • I did an edit on the post to show where I’m still standing.

Browser other questions tagged

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