Skip to content

@Xeoncross /click_words.html
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Convert DOM element words into click-able list of spans
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
var text = $("#select_words").text().trim().split(" ").join("</span> <span>");
$("#select_words").html("<span>" + text + "</span>");
$("span").click(function () {
var $p = $(this).parent('div');
console.log($(this).prev().html());
console.log($(this).html());
console.log($(this).next().html());
$(this).remove();
console.log($p.text());
});
$('span').hover(function()
{
console.log($(this).html());
});
});
</script>
<style type="text/css">
span { background: #ccc; }
</style>
</head>
<body>
<div>
This is normal text.
</div>
<div id="select_words">
This text is selectable and click-able.
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.