I have a CSS rectangle in which they are links.
开发者_高级运维+-----------------------+
| <a href="test"> |
| <a href="toto"> |
|<a href="link3"> |
+-----------------------+
I want to browse all tags in this rectangle and get all their href attributes.
How can I do to browse all element in this rectangle ?
The rectangle and tags have an absolute position ( tags doesn't inherits from rectangle class), so I think we have to browse with coordinates ? Any idea ?
Thanks
Assuming you rectangle has a class, you would do.
$('.rectangleClass a').each(function(i, element) {
console.log(element.href);
});
Ok so I make a possible solution :
- Get the position of the rectangle
- Get all icons of the document
spe_rect.find('.my-icon').mousedown(function(e){
var x_min = spe_rect.offset().left;
var x_max = spe_rect.offset().left + spe_rect.width();
var y_min = spe_rect.offset().top;
var y_max = spe_rect.offset().top + spe_rect.height();
console.log('X Min : ' + x_min + ' ' + 'X Max : ' + x_max);
console.log('Y Min : ' + y_min + ' ' + 'Y Max : ' + y_max);
$('#doc a.icon').each(function(i, element){
if ($(element).offset().left > x_min &&
$(element).offset().left < x_max &&
$(element).offset().top > y_min &&
$(element).offset().top < y_max){
console.log($(element).attr('href'));
}
});
});
精彩评论