How to get the last class of an element?

I need to get the last class of an element, is there a simple way?

by Thulasi Ram.S

HTML

<div class="Result">
    </div>
    <div id="lastClassTest" class="Purple Bold BackgroundColor">
        I need to get the last class of an element, is there a simple way?
        <br />
        <span class="Green Bold">Click The Button To Get Last Css Class.</span>
    </div>
    <input type="button" id="btnSubmit" value="Submit" />

CSS

.Purple
        {
            color: Purple;
        }
        
        .Bold
        {
            font-weight: bolder;
        }
        
        .BackgroundColor
        {
            background-color: Yellow;
        }
        
        .Result
        {
            color: Maroon;
            font-weight: bold;
        }
        
        .Green
        {
            color: Green;
        }

JavaScript

$(document).ready(function () {
            $('#btnSubmit').click(function () {
                var cssClass = $('#lastClassTest').attr("class").split(" ");
                $('.Result').html(cssClass.length > 0 ? ('last class of an element is ' + cssClass[cssClass.length - 1]) : 'No Css Class Exist');
            });
        });