I'm creating a list of images from a folder, and then I open them in a fancybox... so I have thumnails, big images, and a text link to full image.
<div id="download_image">
<p><a href="images/download/folder/big/<?php echo $file;?>" class="fancybox"><img src="<?php echo $path;?><?php echo $file?>" /></a></p>
<p><a href="images/download/folder/full/<?php echo $file;?>.zip" class="btn-download">DOWNLOAD</a></p>
</div>
Then I'm getting images path by jquery, for each image:
var download_image = jQuery('#download_image');
var images = download_image.find('img');
download_images.each(function(){
var img = jQuery(this);
var img_source = img.attr('src');
Now I need to get the url of the "btn-download" link for each image... but I don't know which selector must I use! Any advice?
Differentiate the concepts of ID selector and class selector: The only difference between them is that “id” is unique in a page and it is applied to one HTML element while “class” selector can apply to multiple HTML elements.
In jQuery, the class and ID selectors are the same as in CSS. If you want to select elements with a certain class, use a dot ( . ) and the class name. If you want to select elements with a certain ID, use the hash symbol ( # ) and the ID name.
The .class selector selects elements with a specific class attribute. To select elements with a specific class, write a period (.) character, followed by the name of the class. You can also specify that only specific HTML elements should be affected by a class.
Try this
$('a[class=btn-download]').attr('href')
Use $('.btn-download')
to select an element by class.
If you want to get the href attribute then simply use:
var href = $('.btn-download').attr('href');
To loop through each element use:
$('.btn-download').each(function(){
var href = $(this).attr('href');
// do something with href
})
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