Hi there,
I have a web page with an include to a news article. So the whole news article is shown on the page. I would like only the first 200 characters to show, not the whole thing, so I have tried using the following code. However, I'm not having any success.
JavaScript
HTML:
Can anyone tell me where I'm going wrong?
Many thanks,
Katie
I have a web page with an include to a news article. So the whole news article is shown on the page. I would like only the first 200 characters to show, not the whole thing, so I have tried using the following code. However, I'm not having any success.
JavaScript
Code:
function limitLength(id,len){
var element = document.getElementById(id);
element.innerHTML = element.innerHTML(substr(0, len));
}
HTML:
Code:
<body onload="limitLength('myDiv',200);">
<div id="myDiv">Div contents</div>
</body>
Can anyone tell me where I'm going wrong?
Many thanks,
Katie