Sunday, 14 May 2017

Uncaught TypeError: $(...).text is not a function

I have a very simple HTML page and I try to execute a query, but I get an exception Uncaught TypeError: $(...).text is not a function.

Here is my selector, which I ran directly from Chrome's developer tools:

$('body > div > div.-layout-h > div.task-tests--label').text()

The result: Uncaught TypeError: $(...).text is not a function

The HTML page where I'm running it is linked above.

I also ran the same query in my Node.js app, using cheerio, but it "worked" there:

const $ = cheerio.load(html);
console.log($(`body > div > div.-layout-h > div.task-tests--label`).text());

Result:
Input:Output: Expected Output:Console Output:

My goal is to get the first element and print out its inner text. Why is it giving me an error in the first case and printing all 4 elements, which match the specified query?



via Lirik

No comments:

Post a Comment