I maintain (but didn’t develop) ASP site that has a comments form on its blog pages.
When a comment is added, the page shows a new div styled with the class “comments-wrap”. If there is no comments yet, that div won’t appear at all. It doesn’t us an ID because there may end up being multiple comments on the page.
I want to add a new div to the page(s) that is empty (maybe using a   or the style display:none) unless the a script detects the presence of the “comments-wrap” class.
For example’s sake, lets call the new div . I’d like it to be present on the page all of the time (eg. ), but the space changes to “Previous Comments” when the “comments-wrap” class is detected on the page.
So far I have:
<script>
function myFunction() {
if ($(".comments-wrap")[0]) {
document.getElementById("comments-previous").innerHTML="Previous Comments";
}
}
}
</script>
If you are using jquery use
.lengthto find the number of elements currently matchedEdit