I have a question about the javascript. I write a function in the javascript and I write the function in .html file.
However, when I click the button, it shows the 'Object doesn't support this property or method' error in IE 8.
Can anyone help me? Thank you.
function colour (colour) {
var selectTxt =
window.getSelection() ||
document.getSelection() ||
(document.selection ? document.selection.createRange().text : ''),
targetHTML = document.getElementById('text'); // text is a id in HTML
targetHTML.innerHTML =
targetHTML.innerHTML.replace(
RegExp(selectTxt),
'<span class="' + colour + '">'+selectTxt+'</span>');
}
// HTML
<input type="button" onclick="colour('green')" value="Green"/>
<p id='text'>I live in ABC and I am working in ABC company.</p>