github.com/MontFerret/ferret@v0.18.0/pkg/stdlib/html/elements_count.go (about) 1 package html 2 3 import ( 4 "context" 5 6 "github.com/MontFerret/ferret/pkg/runtime/core" 7 "github.com/MontFerret/ferret/pkg/runtime/values" 8 ) 9 10 // ELEMENTS_COUNT returns a number of found HTML elements by a given CSS selector. 11 // Returns an empty array if element not found. 12 // @param {HTMLPage | HTMLDocument | HTMLElement} node - Target html node. 13 // @param {String} selector - CSS selector. 14 // @return {Int} - A number of matched HTML elements by a given CSS selector. 15 func ElementsCount(ctx context.Context, args ...core.Value) (core.Value, error) { 16 el, selector, err := queryArgs(args) 17 18 if err != nil { 19 return values.None, err 20 } 21 22 return el.CountBySelector(ctx, selector) 23 }