Hi Samuel,

Sorry about the problems you're having with the code. The .lt() and .gt() methods were removed from jQuery shortly after the book was published. In their place, you can use the :lt() and :gt() selectors or the .slice() method. The .slice() method is quite versatile, and takes either one or two arguments. To replicate that code using .slice() you could do this:

$table.find('tbody tr').show()
.slice(0, 2)
.hide()
.end()
.slice(5)
.end();


http://docs.jquery.com/Traversing/slice#startend

Hope that helps.


--Karl

____________
Karl Swedberg
www.englishrules.com
www.learningjquery.com




On Dec 30, 2008, at 10:30 PM, Samuel Wu wrote:


Hi, everyone

I started writing jquery from last week with the help from a very good
book Learning Jquery.

I met a problem when reading the book, which has the script:

<code>
$table.find('tbody tr').show()
.lt(2)
.hide()
.end()
.gt(5)
.end();
</code>

Where 2 and 5 are different from the book, but I think it has no
effect to the problem.

I haven't met a lt or gt method before, I can only write
<code>
   $table.find('tbody tr:lt(2)').hide();
   $table.find('tbody tr:gt(5)').hide();
</code>

I tried the author's code, which didn't work on my browser. the
browser said
"TypeError: $("table").find("tbody tr").show().lt is not a function"

I also tried this way:
<code>
var $trow=$table.find('tbody tr')
$trow.lt(2).hide()
<code>

the problem still exists there.

My question is:
Is lt or gt a method used as a  selector ?
If I want to implement the chain actions like the first code, how
could I do that?

Any help is appreciated. thanks very much. Happy new year.

Reply via email to