Response title
This is preview!
toggleClass: function( classNames ) {
jQuery.className[ jQuery.className.has( this, classNames ) ? "remove" : "add" ]( this, classNames );
}
$('something').toggleClass('lipsum')
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>mariuzzo - jQuery toggle button</title>
<style type="text/css">
.unread {border:#000 solid 2px; color:#000}
.read {border:#999 solid 2px; color:#999}
</style>
<script type="text/javascript" src="../jquery.js"></script>
<script type="text/javascript">
$(function() {
$('.toggleRead').click(function(){
var $this = $(this);
if ($this.is('.unread')) {
$this.removeClass('unread').addClass('read').text('Mark as unread');
// do ajax call to mark as READ.
} else if ($this.is('.read')) {
$this.removeClass('read').addClass('unread').text('Mark as read');
// do ajax call to mark as UNREAD.
}
});
});
</script>
</head>
<body>
<button class="toggleRead unread">Mark as read</button>
<button class="toggleRead unread">Mark as read</button>
<button class="toggleRead unread">Mark as read</button>
<button class="toggleRead unread">Mark as read</button>
<button class="toggleRead unread">Mark as read</button>
</body>
</html>
$(".markread").click(function() {
$(this).toggleClass("markunread");
});
$(".markread").click(function() {
$(this).toggleClass("markunread");
$(this).unbind('click');
});
© 2013 jQuery Foundation
Sponsored by and others.