I want to assign unique ids to paragraphs in a HTML file.
How do i do this using loops in a JavaScript?
(assuming that I know the number of paragraphs in it)
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
function count() {
var num = $("p").size();
for (var i = 0; i < num; i++) {
$ "p".innerhtml();
$id = i;
I dont know
if this is right.is this how we assign ids ?
}
}
</script>
</head>
<body>
<h1>Count paragraphs</h1>
<div>
<p>This is paragraph 1.</p>
<p>This is paragraph 2.</p>
<p>This is paragraph 3.</p>
<p>This is paragraph 4.</p>
</div>
<form action="">
<input type="button" value="count" onclick="count()"></input>
</form>
</body>