I'm trying to understand the difference between the data-srcset
and srcset
attributes.
I need to get a photo by the srcset
attribute, but I can only get it using data-srcset
.
I don’t really understand what the problem is, if the principle by which I get it should be similar.
Let's say I have the following plan html
code - html code.
Scenario #1
:
when I try to get by data-srcset
attribute like this:
// class of the whole element
liElements.forEach(liElement -> {
...
// small photo
Element imgElement = liElement.select("img").first(); // img of element
String dataSrcElement = imgElement.attr("data-srcset"); // data-srcset for element of img
//String srcsetElement = imgElement.attr("srcset"); // srcset for element of img
then there is no problem, but when I use the srcset
attribute.
Scenario #2
:
// class of the whole element
liElements.forEach(liElement -> {
...
// small photo
Element imgElement = liElement.select("img").first(); // img of element
//String dataSrcElement = imgElement.attr("data-srcset"); // data-srcset for element of img
String srcsetElement = imgElement.attr("srcset"); // srcset for element of img;
I'm attaching the screenshot as a proof below:
I see that null
. Can anyone suggest what the difference is?
Is it possible to get it somehow by srcset
? If yes, how can this be done in your opinion?
(I need to get the photo for the first product in the existing forEach()
loop)
Thank you in advance for your help.