I’m using jQuery and Lettering.js to wrap each letter in an <h1> with a span and give it a unique ID. I’ve also set contenteditable=true on the <h1> so when I click on it I can edit the text. How would I select the <span> element that is either to the left or right of the cursor, so I could apply styling to it?
Here’s 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>
Would really appreciate any help or advice!
The following will work in all major browsers:
Here’s a live example: http://jsfiddle.net/BATGH/1/