Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / HTML

jQuery fetch last row

4.67/5 (5 votes)
20 Aug 2010CPOL 27.4K  
Fetch first column in last row of html Table
Scenerio: Accessing first td in last row of html table. Also you have to check the content(here need to search 'td1' text) in first td.

Solution:


1. Add Link to Latest jQuery
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>

2. Html Table



Row1 td0Row1 td1
Row2 td1Row2 td1



3. JQuery Script for accessing last row in above table
Firt td containing 'td0', if it contains 'td0' alert message is appeared.

<script><br />
  $(document).ready(function(){<br />
	if($("#Mytable").find("tr:last td:eq(0)").text().indexOf('td1')!= -1)<br />
	    alert('Good Morining,You got td1');<br />
  });<br />
  </script>


In Above script,

$("#Mytable").find("tr:last td:eq(0)").text().indexOf('td1')

Above line searchs text 'td1' in first column of last row in html table with id='Mytable'.

License

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