I want to insert smiley code in text area under cursor position by clicking on images.
There are three images in div #smiles:
And array
var smiles = {
‘happy’: ‘:)’,
‘sad’: ‘:(‘,
‘normal’: ‘:|’
};
Textarea is #text
I don’t know is it ok to use images’ urls for connection with code, or there is better way (for example, by position).
Can you, please, help me to write the code. I will learn by it 🙂
This past question on SO should get you moving in the right direction. Also as the answer states there is a plugin for jQuery that accomplishes this as well.
Once you get the cursor position, you could do something like this:
and then use
to get the code to insert the proper face at the cursor location. There is going to be more code involved, but this is at a simplified level for an example.