diff --git a/goquery.go b/goquery.go index 4595399..2dcd88c 100644 --- a/goquery.go +++ b/goquery.go @@ -109,9 +109,9 @@ func (this *Selection) Find(selector string) *Selection { } // Returns this (same Selection object) -func (this *Selection) Each(f func(int, *html.Node)) *Selection { +func (this *Selection) Each(f func(int, *Selection)) *Selection { for i, n := range this.Nodes { - f(i, n) + f(i, &Selection{[]*html.Node{n}, this.document}) } return this } diff --git a/goquery_test.go b/goquery_test.go index 328d171..4a1df30 100644 --- a/goquery_test.go +++ b/goquery_test.go @@ -35,7 +35,7 @@ func TestFindInvalidSelector(t *testing.T) { if sel.Nodes != nil { t.Error("Expected a Selection object with Nodes == nil.") } - sel.Each(func(i int, n *html.Node) { + sel.Each(func(i int, n *Selection) { cnt++ }) if cnt > 0 { @@ -57,9 +57,9 @@ func TestChainedFind(t *testing.T) { func TestEach(t *testing.T) { var cnt int - sel := doc.Find(".hero-unit .row-fluid").Each(func(i int, n *html.Node) { + sel := doc.Find(".hero-unit .row-fluid").Each(func(i int, n *Selection) { cnt++ - t.Logf("At index %v, node %v", i, n.Data) + t.Logf("At index %v, node %v", i, n.Nodes[0].Data) }).Find("a") if cnt != 4 {