How to give sentence case to sentences through CSS or javascript? [closed]

How to give sentence case to sentences through CSS or javascript?

I've tried these CSS properties but these are different

capitalize    Transforms the first character of each word to uppercase
uppercase   Transforms all characters to uppercase
lowercase   Transforms all characters to lowercase

Edit: 19 FEB 2010

is there any option in jquery to achieve this?

Answers:

Answer

Don't use JavaScript to fix your content. This is inefficient on a scale of ridiculous. Write your content correctly before you publish it or use some coding scheme on the server side. If this is some scheme to fix content that you don't control, such as user supplied, then simply state the content comes from your users and not you.

Seriously, this is going to delay the loading of your page significantly and cause visitors to abandon your site.

Answer
p:first-letter{text-transform:capitalize}

Capitalizes the first word of each sentence

Answer

Something similar to this will work in JavaScript:

function sentenceCase(theText) {
    return theText.toLowerCase().replace(/(^\s*\w|[\.\!\?]\s*\w)/g,function(c){return c.toUpperCase()});

}

Won't work perfectly in ALL cases, but, it might get you somewhere. There are a lot more elegant solutions on back-end languages, typically, though.

Answer

what about:

str = "HeLlo Its aamiR here";
str = str.substr(0,1).toUpperCase()+str.substr(1).toLowerCase()

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us Javascript

©2020 All rights reserved.