Delovar,
<!DOCTYPE HTML>
<html>
<head>
<title></title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(function(){
$(".element").each(function(indx, element){
$(element).attr("id",indx+1);
});
alert($("body").html())
});
</script>
</head>
<body>
<div id = '1' class = 'element'>1</div>
<div id = '2' class = 'element'>2</div>
<div id = '4' class = 'element'>3</div>
<div id = '5' class = 'element'>4</div>
<div id = '7' class = 'element'>5</div>
</body>
</html>