github.com/MontFerret/ferret@v0.18.0/pkg/stdlib/html/element_exists.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  // ELEMENT_EXISTS returns a boolean value indicating whether there is an element matched by selector.
    11  // @param {HTMLPage | HTMLDocument | HTMLElement} node - Target html node.
    12  // @param {String} selector - CSS selector.
    13  // @return {Boolean} - A boolean value indicating whether there is an element matched by selector.
    14  func ElementExists(ctx context.Context, args ...core.Value) (core.Value, error) {
    15  	el, selector, err := queryArgs(args)
    16  
    17  	if err != nil {
    18  		return values.None, err
    19  	}
    20  
    21  	return el.ExistsBySelector(ctx, selector)
    22  }