I'm trying to get the text inside all h2 tags on a page, using the web console.
All I've found says to use each, I've tried
var anArray = []; $('h2').each( function(i,e) { anArray.push($(e).innerHTML); });
But it returns TypeError: $(...).each
is not a function.
I've also tried using
$.each('h2', function(i,e) { anArray.push($(e).innerHTML); });
But again, all I get is TypeError: $.each
is not a function?
The "forEach is not a function" error occurs when we call the forEach() method on a value that is not of type array, Map , or Set . To solve the error, make sure to only call the forEach method on arrays, Map or Set objects. Copied!
The JavaScript exception "is not a function" occurs when there was an attempt to call a value from a function, but the value is not actually a function.
The Javascript error TypeError: "x" is not a function occurs when there is an attempt to call a function on a value or object, which is not actually a function.
1) Paste:
var script = document.createElement('script'); script.src = "https://ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js"; document.getElementsByTagName('head')[0].appendChild(script);
on your console (includes jQuery)
2) Wait 1 sec and paste:
var h2Arr = []; $('h2').each( function() { h2Arr.push($(this).html()); });
Now, all contents of h2 tags of that page should be stored into h2Arr
if you write code like without $() for example
var1.each(function(){}) //its wrong//each function is not defined error $(var1).each(function(){}) //its right
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With