Currently I'm setting up some code to dynamically change a specific button on the page based on information provided in a key. I am relatively new to programming and jQuery/JavaScript and I am thankful for all answers!
Problem: I want to save an URL that is a value of a srcset attribute so that it can be saved to the key for the changing of the button-link. There are a few srcset attributes and my needed value has a unique identifier in the URL (e.g. www.url.com/this-is-a-sample-image/KQ4/... with KQ4 being the unique identifier). The other srcset attributes have KQ6, KQ2, and so on, as an example.
How can I select my needed srcset attribute (as info: it is always in the same position under the <picture> tag) and save it's content to the key?
<div class="unique_img" style="margin-left: 0px;">
<picture>
<source srcset="www.url.com/this-is-a-sample-image/KQ4/..., www.url.com/this-is-a-sample-image/KQ4/... 2x" media="min-width: xx")>
<source srcset="www.url.com/this-is-a-sample-image/KQ6/..., www.url.com/this-is-a-sample-image/KQ6/... 2x" media="min-width: yy")>
<source srcset="www.url.com/this-is-a-sample-image/KQ8/..., www.url.com/this-is-a-sample-image/KQ8/... 2x" media="min-width: zz")>
</picture>
</div>
I have tried various jQuery methods to get my needed srcset selected, but I am not able to search specifically for my KQ4 one:
$("div.unique_img[srcset*=KQ4]")
$("div.unique_img:contains('KQ4')")
$('div.unique_img:nth-child(1)')
$('div.unique_img').find('KQ4')
$('div.unique_img .srcset')
$("img[name*='KQ4']")
Expected outcome would be to get the whole URL from the needed 1st srcset and save it to a specific key. As of now I still haven't been able to figure out how to do it exactly.
A pointer to the appropriate part of the documentation would be enough as well, as I want to learn JavaScript!