zoit zoit - 1 year ago 63
Javascript Question

Retrieving data from span with jquery and c#

I'm trying to retrieve some values from span which are inside a td. I have this function:

function reorder() {
alert("Entrando en reorder");
strorder = "";
var totalid = $('#ctl00_ContentPlaceHolder1_grdResultados tr td input').length;
for (var i = 0; i < totalid; i++) {
strorder = strorder +$('#ctl00_ContentPlaceHolder1_grdResultados tr td span')[i].text()+"*"+ $('#ctl00_ContentPlaceHolder1_grdResultados tr td input')[i].getAttribute("value") + "|";
//strorder = window.location.href;

And the source code is this (a piece of the code):

<table class="table table-hover tablaDimensiones" cellspacing="0" border="0" id="ctl00_ContentPlaceHolder1_grdResultados" style="border-collapse:collapse;">
<th scope="col">
<a href="javascript:__doPostBack(&#39;ctl00$ContentPlaceHolder1$grdResultados&#39;,&#39;Sort$titulo&#39;)">Título</a>
<th scope="col">Opciones</th>
<span id="ctl00_ContentPlaceHolder1_grdResultados_ctl02_lblTitulo">Dimension1</span>
<input type="hidden" name="ctl00$ContentPlaceHolder1$grdResultados$ctl02$hdnid" id="ctl00_ContentPlaceHolder1_grdResultados_ctl02_hdnid" value="1" />
<a id="ctl00_ContentPlaceHolder1_grdResultados_ctl02_cmdEditar" title="Editar" class="btn btn-default" href="javascript:__doPostBack(&#39;ctl00$ContentPlaceHolder1$grdResultados$ctl02$cmdEditar&#39;,&#39;&#39;)">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
<a onclick="return confirm(&#39;¿Desea elimnar la dimensión?&#39;);" id="ctl00_ContentPlaceHolder1_grdResultados_ctl02_cmdEliminar" href="javascript:__doPostBack(&#39;ctl00$ContentPlaceHolder1$grdResultados$ctl02$cmdEliminar&#39;,&#39;&#39;)">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>


How can I do it?, because in this way I don't have what I want. Regards

Answer Source

This may be optimistic

 $td = $('.tablaDimensiones tr td');

        var spans = $td.find('span');
        var inps = $td.find('input');

        var len = spans.length;

        var sortorder = "";

        for (var i = 0; i < len; i++) {
            sortorder += spans.eq(i).text() + "*" + inps.eq(i).text() + "|";