home

Javascript Length

Here we are going to discussing about how to find the length of string, it is very simple thing to know the length of string check the below code with description. okay let see the code below in the first line button code is including on click event (event name is myfunction), with using this myfunction in java script code called function name called myfunction and creating variable called "str" value is "hello Good Morning" with length property. one more thing getting the value from getElementById(display) value will display in which div has display id.

div code with id and button with on click event

<div id="display" title="click on tha button you will get the lenght of string">click on the button you will get the length of string</div>
<button onclick="myfunction()">button</button>

Java Script function and properties with values

<script>
function myfunction(){
var str="Hello Good Morning!";
var n=str.length;
document.getElementById("display").innerHTML=n;
}

</script>