Follow this blog

Wednesday, September 7, 2011

Change text to UPPERCASE with jQuery

How to convert text to uppercase with jQuery? It is very easy, just follow steps in this brief tutorial. To make things easy this article will provide two demo examples with jQuery code.

jQuery uppercase - change text to uppercase in messagebox


Click here to uppercase

In this demo text "To uppercase with jquery!" is changed to uppercase "TO UPPERCASE WITH JQUERY!". When link "Click here to uppercase" is clicked changed text is showed in messagebox.

Explanation for uppercase:

jQuery have toUpperCase method which convert text to UpperCase. Here is a sample code:

<script src="" type="text/javascript"></script>

<div id="target">
  Click here for uppercase

    $('#target').click(function () {
        var strVal = 'To uppercase with jquery!'

First line is reference on jQuery library which every page using jQuery must have.

Then we have "Click here for uppercase" link with id target.

Inside script tag we have function which is fired when item with id "target" is clicked. Variable strVal is changed to uppercase with method toUpperCase() and showed in messagebox.

Change text in input textbox to uppercase jQuery

Change to uppercase

Above is a link "Change to uppercase" which change text in input text box to uppercase.


 <div id="Change">
  Change to uppercase
<input value="to uppercase" type="text" id="inpChng" />

    $('#Change').click(function () {
        var strVal = $("#inpChng").val();

In the code above when link in div with id "Change is clicked" value from input text control is taken and changed to uppercase.

No comments: