Skip to content Skip to sidebar Skip to footer

Selecting Text Within A Div, Changing Button When Text Is Highlighted (deselect When Its Unhighlighted)

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

Solution 1:

The original script you have is not far off. I would suggest using

The resulting code is longer than what you've got but is more logical, modular and readable.

Also, it's document.getElementById() rather than document.GetElementById().

Demo: http://jsfiddle.net/9zXg6/6/

Code not contained in linked answers:

functiongetSelfOrAncestorWithClass(node, theClass) {
    while (node) {
        if (hasClass(node, theClass)) {
            return node;
        } else {
            node = node.parentNode;
        }
    }
    returnnull;
}

Post a Comment for "Selecting Text Within A Div, Changing Button When Text Is Highlighted (deselect When Its Unhighlighted)"