Skip to content

Instantly share code, notes, and snippets.

@s0ren
Last active September 8, 2015 08:48
Show Gist options
  • Save s0ren/f125a22f51d71d7b7f34 to your computer and use it in GitHub Desktop.
Save s0ren/f125a22f51d71d7b7f34 to your computer and use it in GitHub Desktop.
Hvordan man gennemløber flere elementer i jquery
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("p").each(function(){
var x = $(this).position();
alert("Top position: " + x.top + " Left position: " + x.left);
});
});
});
</script>
</head>
<body>
<p>This is a paragraph.</p>
<p> ... and this en anden paragraf </p>
<button>Return the top and left position of the p element</button>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment