I use jQuery and Lettering.js to wrap each letter in <h1>with span and assign it a unique identifier. I also set contenteditable=trueto <h1>, so when I click on it, I can edit the text. How would I select an element <span>that is either left or right of the cursor, so I could apply a style to it?
Here is my code
<head>
<style media="screen" type="text/css">
body {text-align: center}
</style>
<script src="scripts/jquery.js" type="text/javascript" charset="utf-8"></script>
<script src="scripts/lettering.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
$("h1").lettering();
});
</script>
</head>
<body>
<h1 contenteditable="true" >Click me!</h1>
</body>
I would really appreciate any help or advice!
source
share