Skip to content

Instantly share code, notes, and snippets.

@cnocon
Created May 14, 2013 23:31
Show Gist options
  • Save cnocon/5580574 to your computer and use it in GitHub Desktop.
Save cnocon/5580574 to your computer and use it in GitHub Desktop.
The caption code we use in our CSS. Authored by Erik Runyon.
$(window).load(function() {
$('.image-right img,.image-left img,.image-default img').each(function(i,e){
var $this = $(this), /*1*/
$parent = $this.parent('p'); /*2*/
if($parent.text().trim().length > 0) { /*3*/
$parent.addClass('captioned').css({ width: $this.outerWidth() }); /*4*/
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment