I’m trying to figure out how Facebook does it. I know they use textarea’s in there comments and status features, but if I tag someone in a post or something, it will highlight that selection of text in the textarea with a light blue background. I know textarea’s or last I knew rather at least, that this wasn’t possible with this type of element, so how are they doing it? Whats the technique? anyone have any idea? Im banking on some smoke and mirrors as to how its being done, but not sure how?
Share
Although it is using a
textareain some fashion, the bulk of the magic is done withdivs and CSS. I pulled this from Safari’s Web Inspector:The important elements:
div.highlighterand its descendantspan.highlighterContent. Notice that it styles abelement as the highlighted content.onfocushandler for the actualtextareaelement. Somewhere in there, it creates aTextAreaControlobject, which seems to create an object somewhere else in the DOM, since thetextareacontent itself is not being updated.input[type=hidden].mentionsHiddenthat submits custom data to the server so it knows who you actually mentioned.This is totally Facebook specific, but maybe it gives you some ideas for what you’d like to do.