I’m not able to figure out how to count all the characters of an html string using jquery:
For example:
<link rel="stylesheet" type="text/css" href="style.css" id="basic">
I wanna do something like:
var object = $('#basic');
var characters = object.numberOfCharacters;
The answer should be = 67
3
Answers
You can simply do:
There isn’t really a jQuery function available for this purpose, but luckily Vanilla-Javascript is capable of getting the
.outerHTML
property directly from the (first) selected DOM element of the jQuery object.You can get the ‘outer’ HTML property to get the tag/element selected and then count the length of that element.
See sample code below
You can try this in jquery