0

I'm trying to select some elements from this website: https://www.pexels.com/

For example I try this simple selector to match all the divs elements inside the div father container with "photos__column" class:

$('div.photos__column div')

But as a result it only selects the first of all of them, why is this happening?

Thanks in advance.

1
  • Can you post the relevant HTML instead of a link to the site? That will make this more useful for future visitors since the HTML can change at any time on that site. Commented May 22, 2020 at 23:32

2 Answers 2

4

$ could be anything.

Does this site have jQuery at all? You can check it in the browser console via

$.fn.jquery

Querying with native DOM API

document.querySelectorAll('div.photos__column div')

works.

Sign up to request clarification or add additional context in comments.

1 Comment

To elaborate on this, if you're just using the Chrome console, $ is an alias for document.querySelector, and $$ is document.querySelectorAll. The former only selects one element. Indeed, that site doesn't seem to have jQuery.
0

$('div.photos__column div') return an array with all elements with this pattern "div.photos__column div" but whene you call a function like text() , the function text use only the firest rsult of array

if you want to do an operation on all selected element , can you use :

$('div.photos__column div').each(function( index ) {
  console.log( index + ": " + $( this ).attr("src") );
});

or if you want to select element by index , you can call element by hir index for example : $('div.photos__column div')[2]

can you use this query to get all img source from the home page :

var allimegs = document.querySelectorAll(".photo-item__img");
var newsrc = [] ;for(var i = 0;i<allimegs.length;i++){
    newsrc[i] = allimegs[i].getAttribute("src"); 
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.