Issue
I am trying to select a text/character from an input tag and when i press a bold button, selected text should change to bold and when the button is pressed again the selected text should change to normal.
here is my code but its not working.
<body>
<input type="text" name=inp id="inp">
<button onclick="getSelectedText();"><b>B</b></button>
<script>
document.getElementsByTagName('input').mouseup(function(){
getSelectedText().style.fontWeight="bold";
});
function getSelectedText() {
if (window.getSelection) {
return window.getSelection().toString();
} else if (document.selection) {
return document.selection.createRange().text;
}
return '';
}
</script>
Solution
i think: the function returns a string, it is not an element in the document and has no style attribute
Answered By - 6fa Answer Checked By - Mary Flores (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.