Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Highlight paragraph on click?
How do I set up to automatically highlight any paragraph or text area of particular types (a .pre or .bc) on click?
Last edited by jonathanbrickman0000 (2014-06-20 15:13:03)
Offline
Re: Highlight paragraph on click?
You will have to use feature detection and non-standard APIs to get something selected. Along the lines of:
// Trigger the handler when 'pre' is clicked.
$('pre').on('click', function() {
// Get raw Element object of the target jQuery object and define needed variables.
var text = $(this).get(0), range, selection;
// Check if the browser is Internet Explorer.
if (window.document.body.createTextRange) {
// If so, selected the element's content.
range = window.document.body.createTextRange();
range.moveToElementText(text);
range.select();
} else if (window.getSelection) {
// Any other browser than IE.
selection = window.getSelection();
range = window.document.createRange();
range.selectNodeContents(text);
selection.removeAllRanges();
selection.addRange(range);
}
});
The above uses jQuery for event handling.
Offline