Skip to content

Instantly share code, notes, and snippets.

@rwaldron
Forked from cowboy/jquery.ba-logselector.js
Created October 29, 2010 15:17
Show Gist options
  • Save rwaldron/653733 to your computer and use it in GitHub Desktop.
Save rwaldron/653733 to your computer and use it in GitHub Desktop.
/*!
* jQuery log selector - v0.1pre - 10/22/2010
* http://benalman.com/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
// Log the selector used to select elements to each selected element,
// otherwise to the body. Hover over logged selectors to highlight
// stuff all fancy-like (note: don't select SPAN elements because this
// creates them all over the place!)
(function($){
$.fn.logSelector = function() {
var elems = $( '<span>' + this.selector + ' [' + this.length + ']</span>' )
.appendTo( this.length ? this : 'body' );
this.length && elems.hover(function(e){
elems.parent().andSelf().toggleClass( 'hover', e.type === 'mouseenter' );
});
return this;
};
})(jQuery);
/*
Use with this CSS:
.hover {
background: #afa;
}
span {
padding: 1px;
display: block;
font-weight: 400;
cursor: default;
}
span.hover {
color: #fff;
background: #0a0;
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment