javascript - How do I find the absolute position of all hyperlink elements using jQuery? -


i absolute position of html hyperlink elements. write jquery find absolute position of each link element following:

jquery('a').each(function() {     var ellink = jquery(this);     console.log(this.text + ' => ' + this.href + ' ' + json.stringify(ellink.offset()) + ' top:' + ellink.css('top') + ' left:' + ellink.css('left')) }); 

however, doesn't work. example, on page of http://www.actuino.fr, there link called "le crawler" give me top = 0 , left = 0, while "contact" link give me correct position. no links hidden.

so how absolute position of these links? thank you!

i don't think there should issues regarding getting .offset() of element whether absolute,relative, fixed or static positioned.

but 1 thing noticed:

in below example have 3 anchors , 1 of them hidden although absolutely positioned top,left has been assigned 0 browser.

jquery('a').each(function() {      var ellink = jquery(this);      $(document.body).append('<pre>'+this.href + ':::<--href:::.offset():::-->' + json.stringify(ellink.offset()) +'</pre>')  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <a href='#123' style='margin:40px 0 0 80px;'>link 1</a>  <a href='#456' style='position:absolute; right:0; bottom:50px;'>link 2</a>  <a href='#789' style='display:none; position:absolute; left:0; bottom:50px;'>link 2</a>


Comments

Popular posts from this blog

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -