I have this script from fiddle: http://jsfiddle.net/83T7U/5/. It changes the button name from 'Reply' to 'Quote' when some text is selected within a specific DIV. However, it only works on clear text (ie. without any span, bold, italic, etc. tags).
I'd like to change this script so that it works with HTML tags too. So the approach needs to be changed and the easiest way should be to target the button, not parent/child text within a DIV.
So I created a new script (but it's not complete): http://jsfiddle.net/c8UbV/ that should change button name from 'Reply' to 'Quote' as soon as a text within a DIV is highlighted (and change it back to Reply when text is unhighlighted). But it's not working (because it's not complete...). How would it be possible to make it work correctly?
HTML:
<div id="m2560" class="yellow">DIV1: First <span style="color:red">some red text for</span> you to select
<br>
<button id="msg2560">Reply</button>
</div>
<br>
<div id="m2900" class="green">DIV2: <b>Second some bold</b> test text for you to select
<br>
<button id="m2900">Reply</button>
</div>
<br>
<div id="msg3022" class="blue">DIV3: <i>Third some italic test</i> text for you to select
<br>
<button id="msg3022">Reply</button>
</div>
JavaScript:
function changeButton() {
// for now this script only checks if text is selected
var text = "";
if (typeof window.getSelection != "undefined") {
//? it should probably be document.GetElementById('button_id').innerHTML='Quote';
} else if (typeof document.selection != "undefined" && document.selection.type == "Text") {
//? it should probably be document.GetElementById('button_id').innerHTML='Quote';
}
return text;
}
document.GetElementById('msg***').onclick = changeButton;