javascript - Is there a JS equivalent to CSS text-transform: capitalize? -


i've got hidden <section /> comprised of divs contain content stuffed jquery ui dialog. on document.ready want loop through divs, take id of each respective div, replace dashes spaces, capitalize each word, , store in title variable. then, i'm going use in object literal gets put dialogs[] array. sounds simple, right?

stripped down version of html:

<section id="dialog-content" class="hidden">      <div id="some-dialog">         // awesome dialog content here     </div>      <div id="another-dialog">         // awesome dialog content here     </div>      <div id="modal-dialog">         // awesome dialog content here     </div>  </section> 

stripped down version of javascript:

var dialogs = [],     $container = $("#dialog-content");     $content = $container.find("> div");  $content.each(function (i)  {            var $this = $(this),         id = $this.attr("id"),         title = id.replace(/\-/g, " ");      console.log(title);      dialogs[dialogs.length] =      {          trigger: $("#" + id + "-trigger"),          title: title,          content: $this.html()      }; }); 

btw - know can use $.data() , add custom properties divs, wanted minimal of markup possible, , curious specific possibility. it's not example, question @ hand.

to re-iterate, question is:

how can capitalize each word in variable via javascript, text-transform: capitalize; in css?

you write function it. here simple regex-based function:

function capitalize(text) {     return text.replace(/\b\w/g , function(m){ return m.touppercase(); } ); } 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -