Question

I've a website with N forms.

Foreach form I want to choose all the input elements. How can I do that see (1) + (2) in the code comments?

doc = CQ.CreateFromFile("sample.html");
doc["form"].Each(e =>
        {
            // 1) This returns only first level
            IEnumerable<IDomElement> inputs = e.ChildElements;

            // 2) This refers to all the document again
            CQ currentForm = e.Cq().Select["input"]
        }

Another question: why DomElement.Cq() refers to the whole document and not the current element? How can I make it refer to the current element?

Thanks

Was it helpful?

Solution

Easiest to just let the jQuery methods do the work for you:

IEnumerable<IDomElement> inputs = e.Cq().Find("input");

The Select method always selects against the entire dom, it's analagous to just using $(...) with jQuery. Find selects only from within its context, as in jQuery.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top