How to loop through LI items in UL, get specific attributes, and pass them via $.ajax data
Posted
by
Ahmed Fouad
on Stack Overflow
See other posts from Stack Overflow
or by Ahmed Fouad
Published on 2012-06-01T10:37:53Z
Indexed on
2012/06/01
10:40 UTC
Read the original article
Hit count: 364
JavaScript
|jQuery
Here is my HTML code:
<ul id="gallery">
<li id="attachment-32" class="featured"><a href="..." title=""><img src="..." alt="" /></a></li>
<li id="attachment-34"><a href="..." title=""><img src="..." alt="" /></a></li>
<li id="attachment-38"><a href="..." title=""><img src="..." alt="" /></a></li>
<li id="attachment-64"><a href="..." title=""><img src="..." alt="" /></a></li>
<li id="attachment-75"><a href="..." title=""><img src="..." alt="" /></a></li>
<li></li>
</ul>
Here is my sample ajax request:
$.ajax({
url: '/ajax/upload.php',
type: 'POST',
data: { ... },
success: function(data){
}
});
Here is what I want to achieve.
How to get the attachment number in ID attribute for every LI inside the gallery UL only when an ID attr is there and pass them via ajax data in this way:
{ attached : '32,34,38,64,75' }
if there is a better way of doing this let me know I want to pass the list items which contain attachments to process.How to get the list item LI which has class of featured e.g. { featured_img : .. } and pass the attachment ID number if featured LI exists, and if none of list items is featured pass featured_img with 0. So i know how to process it via php in the request.
Any help is appreciated.
Thank you.
© Stack Overflow or respective owner