2
Show amount of LI within a UL.
I have the following HTML:
<ul class="rodapeUlCat margin-top-25">
<li><h3><a href="/paginaSYS">tituloMenuSYS</a></h3></li>
<li><h3><a href="/paginaSYS">tituloMenuSYS</a></h3></li>
<li><h3><a href="/paginaSYS">tituloMenuSYS</a></h3></li>
<li><h3><a href="/paginaSYS">tituloMenuSYS</a></h3></li>
<li><h3><a href="/paginaSYS">tituloMenuSYS</a></h3></li>
<li><h3><a href="/paginaSYS">tituloMenuSYS</a></h3></li>
<li><h3><a href="/paginaSYS">tituloMenuSYS</a></h3></li>
<li><h3><a href="/paginaSYS">tituloMenuSYS</a></h3></li>
<li><h3><a href="/paginaSYS">tituloMenuSYS</a></h3></li>
</ul>
<div class="rodapeCat">Outras Categorias (16)</div>
What I want to do is where it says Other Categories (16) in "16", it shows the amount of li
which is contained within the ul
.
I made a Jquery:
$( ".rodapeUlCat" ).append( $( "<li>" ) );
var n = $( "li" ).length;
$( ".rodapeCat" ).text( + n + );
I would like to know what I did wrong. The length
counts the elements, right? Maybe the mistake is the append
, but I don’t know what to put in place.
You don’t need to put the
+
to write an unconnected text– Erlon Charles
The mistake is the
+ n +
, this is a syntax error and should be shown in the browser console. Use.text(n)
, or.text('Categorias(' + n + ')')
.– bfavaretto