how to increase and decrease font size dynamically in jquery

Description:
Here i will explain how to increase or decrease font size using jquery. It is easy and simple way to do this use below function:


<script type="text/javascript">
        $(document).ready(function () {
            var divtxt = $('#fontdiv');
            // Increase Font Size
            $('#btnincfont').click(function () {
                var curSize = divtxt.css('fontSize');
                var newSize = parseInt(curSize.replace("px", "")) + 1;
                $(divtxt).css("fontSize", newSize + "px");
            });
            // Decrease Font Size
            $('#btndecfont').click(function () {
                var curSize = divtxt.css('fontSize');
                var newSize = parseInt(curSize.replace("px", "")) - 1;
                $(divtxt).css("fontSize", newSize + "px");
            })
        });
    </script>

<input type="button" id="btnincfont" value=" + " />
<input type="button" id="btndecfont" value=" - " />

No comments:

Post a Comment