I would try to find all "absolute" elements in my page; with jQuery I though it would be something like
$('[position="absolute"]')
but on ff 10.0.2 I cannot find an element...
Also, I cannot run the exaple code on http://api.jquery.com/attribute-equals-selector/ Is there something wrong on this syntax?
Use element. getBoundingClientRect() property to get the position of an element.
The correct approach is to use element. getBoundingClientRect() : var rect = element. getBoundingClientRect(); console.
The positioning of an element can be done using the top, right, bottom, and left properties. These specify the distance of an HTML element from the edge of the viewport. To set the position by these four properties, we have to declare the positioning method.
The position CSS property sets how an element is positioned in a document. The top , right , bottom , and left properties determine the final location of positioned elements.
Try this:
$("*[style*='position:absolute']").each (function () {
alert($(this).html());
});
Demo : http://jsfiddle.net/XRRbr/1/
More info: http://api.jquery.com/attribute-contains-selector/
Building on Nicola's answer, you can also extend jQuery's selector engine.
$.extend($.expr[':'],{
absolute: function(el) {
return $(el).css('position') === 'absolute';
},
relative: function (el) {
return $(el).css('position') === 'relative';
},
static: function (el) {
return $(el).css('position') === 'static';
},
fixed: function (el) {
return $(el).css('position') === 'fixed';
}
});
Then you can you do things like this.
$(':absolute');
$('div.sidebar:relative');
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