Skip to content

Instantly share code, notes, and snippets.

@arslanfarooq
Created January 17, 2017 10:45
Show Gist options
  • Select an option

  • Save arslanfarooq/f6079b4442261ad67575ac282ec2c86b to your computer and use it in GitHub Desktop.

Select an option

Save arslanfarooq/f6079b4442261ad67575ac282ec2c86b to your computer and use it in GitHub Desktop.
<script type="text/javascript">
jQuery(document).ready(function($) {
var ele = $('h3');
ele.each(function() {
$(this).text(toProperCase($(this).text()));
});
function toProperCase(str)
{
var noCaps = ['of','a','the','and','an','am','or','nor','but','is','if','then',
'else','when','at','from','by','on','off','for','in','out','to','into','with'];
return str.replace(/\w\S*/g, function(txt, offset){
if(offset != 0 && noCaps.indexOf(txt.toLowerCase()) != -1){
return txt.toLowerCase();
}
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
});
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment