Hello,

Consider the code snippet at the end of the post.

It alert()s me by returning the selected text.

The problem is that window.getSelection() only returns plain text. No
indication of the html tags, of the classes, nor any kind of DOM.

I think that jQuery has something more complete than window.getSelection(),
but I was not able to find it reading the docs and searching Google. I'm a
beginner with jQuery, as you've probably figured right now.

The ultimate goal would be to filter the selection so that only text
enclosed in given classes (say loremipsum and third in my example) are
returned. I'd take it as a bonus, but I can figure this part by myself
server-side.

Cheers,
Stéphane

<html>
<head>
<script type="text/javascript">
function getActiveText(e) {
        var text = window.getSelection();
        alert(text);
}
</script>
</head>
<body>
        <p class="lorem">Lorem ipsum dolor sit amet, magna massa aliquet in
libero, a suscipit suspendisse ac penatibus, lectus donec consequat, sed
justo</p>
        <p> javascript:getActiveText(); Alert me! </p>
</body>
</html>

-- 
View this message in context: 
http://www.nabble.com/-Beginner-alert--How-do-I-output-the-selected-part-of-the-DOM-in-a-web-page-in-a-JS-alert%28%29--tp20755509s27240p20755509.html
Sent from the jQuery General Discussion mailing list archive at Nabble.com.

Reply via email to