Click here to Skip to main content
15,881,757 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

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 20: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

$(document.getElementById("tblEvent").rows[17].cells[0].innerHTML+' span').text()
 
Share this answer
 
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.
you can use for read span

$('#spanId').text();
 
Share this answer
 

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