1
I would like to know how many characters it contains within this H2, which in this case ex: <h2 class="h2">Ola Mundo</h2>
contains 9 characters.
1
I would like to know how many characters it contains within this H2, which in this case ex: <h2 class="h2">Ola Mundo</h2>
contains 9 characters.
1
In Javascript Strings have a property .length
that gives you exactly what you want.
DOM objects have a property innerHTML
which gives its contents (or innerText
if you want to ignore HTML).
Combine that with a method that will fetch the object from the DOM you get what you want:
var length = document.querySelector('h2.h2').innerHTML.length;
Browser other questions tagged jquery
You are not signed in. Login or sign up in order to post.
All <H2> goes
var contador = $('h2').length
and it’s classy like thisvar contador = $('h2[class*=h2]').length
is jquery.– KingRider
Thank you again Sergio !!!!
– João Filipe