Click here to Skip to main content
14,735,092 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I fill table like this. I want toread value of span in jquery/javascript

<table>
<tr><td><span id="span1" >0.00</span></td>
<td><input onchange="display(this)" placeholder="0.00" />
</td>
</tr>
</table>

 function display(lnk) {
            var row = lnk.parentNode.parentNode;
            alert(row.rowIndex);
           alert($('#row.cells[0]').text());    
            var rowIndex = row.rowIndex - 1;
        }
Posted
Updated 5-Oct-20 21:03pm
v3
Comments
Sinisa Hajnal 8-Jan-16 6:25am
   
You cannot access template element because it doesn't exist in rendered page. Instead, see the source code of the page (in the browser) and target suitable id. You may have to change default id of the txtLiftedQty by adding rowID or index or something so it is unique on the page (unless the server is already doing it).

Finally, if your getelementbyid works, why do you need jQuery to access it? jQuery id access looks like $('#ID')...you will still have to create that id...or you could use the above code with getelementbyid and just wrap received object in jQuery (i.e. $(row) )
Member 7909353 8-Jan-16 6:44am
   
Like this
var row = document.getElementById(rowId + "_txtLiftedQty_" + rowIndex);

alert("abc=" + $('#row').val());
?
It shows abc=undifined
Member 7909353 8-Jan-16 6:54am
   
Actually I do not want to use innerHTML after getting element.
Member 7909353 8-Jan-16 7:04am
   
alert(row.id) gives
ContentPlaceHolder1_rptFPS_rptCommodity_0_rptMonth_0_gvPayment_0_txtLiftedQty_0
CMEDINAS 5-Feb-16 10:12am
   
youy can use... $("#span1").text()

you can use for read span

$('#spanId').text();
   
$(document.getElementById("tblEvent").rows[17].cells[0].innerHTML+' span').text()
   
Comments
Richard Deeming 6-Oct-20 5:24am
   
An unformatted, unexplained code-dump which uses exactly the same method as the existing solution.

You have added nothing to the discussion.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900