Web Development with jQuery®

(Elliott) #1

(^474) ❘ CHAPTER 22 CREATING A SIMPLE WYSIWYG EDITOR




















The CSS remains unchanged from the previous example, so refer to it if needed. The updated
markup is, however, enhanced with the updated JavaScript (Example 22-3.js):
$(document).ready(
function()
{
$('div#container').focus();
$('button.toolbar-btn').click(
function()
{
var data = this && $(this).data && $(this).data();
if (data && data.format && document.execCommand)
{
document.execCommand(data.format, false, null);
$('div#container').focus();
}
}
);
$('select.toolbar-ddl').change(
function()
{
var data = this && $(this).data && $(this).data();
if (data && data.format && document.execCommand)
{
[http://www.it-ebooks.info](http://www.it-ebooks.info)
Free download pdf