I'm not sure what you mean. Try this:
Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">
function insertNthChar(string, chr, nth){
var sl = string.length, i = 0, output = '';
for (i; i < sl; ++i){
if (i && !(i % nth)){
output += chr;
}
output += string.charAt(i);
}
return output;
}
</script>
</head>
<body onload="var d = document.getElementById('mycoupon'); d.innerHTML = insertNthChar(d.innerHTML, '-', 4);">
<div id="mycoupon">
The current code works perfectly with a pop up alert, but I want it to target an ID instead. The ID is 'mycoupon'. Does anyone know how to do this?
</div>
</body>
</html>
If that's not what you're looking for, please be more specific.
Bookmarks