jQuery addClass example
Change class name on click in jQuery
by Abhishek Nandgaonkar
HTML
<div contenteditable="true">say <img id="test" class="self-closing-tag"...
CSS
.annotated {
background: #FFFF99;
border-width: 1px;
border-color: black;
border-style: dashed;
padding: 2px
}
.tags {
margin: 0;
padding: 0;
right: 24px;
bottom: -12px;
list-style: none;
}
.tags div, .tags div {
float: left;
height: 24px;
line-height: 24px;
position: relative;
font-size: 11px;
}
.tags div {
margin: 2px 5px 2px 12px;
padding: 0 10px 0 12px;
background: #0078d7;
color: #fff;
text-decoration: none;
-moz-border-radius-bottomright: 4px;
-webkit-border-bottom-right-radius: 4px;
border-bottom-right-radius: 4px;
-moz-border-radius-topright: 4px;
-webkit-border-top-right-radius: 4px;
border-top-right-radius: 4px;
}
.tags div:before {
content: "";
float: left;
position: absolute;
top: 0;
left: -12px;
width: 0;
height: 0;
border-color: transparent #0078d7 transparent transparent;
border-style: solid;
border-width: 12px 12px 12px 0;
}
.tags div:after {
content: "";
position: absolute;
top: 10px;
left: 0;
float: left;
width: 4px;
height: 4px;
-moz-border-radius: 2px;
-webkit-border-radius: 2px;
border-radius: 2px;
background: #fff;
-moz-box-shadow: -1px -1px 2px #004977;
-webkit-box-shadow: -1px -1px 2px #004977;
box-shadow: -1px -1px 2px #004977;
}
.tags.ic div {
background: #003399;
}
.tags.ic div:before{
border-color: transparent #003399 transparent transparent;
}
JavaScript
$('.self-closing-tag').bind('contextmenu', function(e) {
alert('Editor plain text: ' + $(event.target).parent().text());
return false;
});