From the jQuery API Documentation.
.html()
Get the HTML contents of the first element in the set of matched elements or set the HTML contents of every matched element.
How is it determined if this function will match the first element or all the elements that are matched? Consider this html.
<body>
<p id="simple">The first paragraph</p>
<p id="simple">The second paragraph</p>
</body>
If I use the following jQuery
$(document).ready(function() {
$("p:#simple").html("I changed to this");
});
I will get:
I changed to this
The second paragraph
This result is the same if I change "p:simple"
to be "#simple"
However if change the html to use classes instead of ids
<p class="simple">The first paragraph</p>
<p class="simple">The second paragraph</p>
and change "p:#simple"
to be either "p:.simple"
or "p"
or ".simple"
the result will be
I changed to this
I changed to this
Why is this?