I am studying programming by this book: Learning to Program (written by Steven Foote).
The book says in order to create an “array” of all the images on a Facebook page, go to “Console” on Chrome Dev Tools on Facebook and type this: var images = document.querySelectorAll('div.userContentWrapper img);
But, this code doesn’t show me any array (it just ends up with “undefined”).
it’s probably that Facebook has changed its HTML as this book also says.
Does anyone know how to get an array on Facebook page?
Actually it still works, just make sure you close add the single quote at the end (before the closing bracket).
Why it is giving you ‘undefined’ because it is a NodeList. Simply type images after it to see the object. You can then cycle through it to get the images using a for-loop or whatever. Or access a specific image using images to get the forth image.
Because that line of code is simply assigning something (a list of images) to a variable (‘images’). You are not actually outputting anything to the console. To see the list instantly you could type console.log(document.querySelectorAll('div.userContentWrapper img)) although this would just log it to the terminal (i.e. you wouldn’t be able to do anything with the list of images as they haven’t been stored anywhere)