Increase and Decrease font size using jQuery

This tutorial explains how to increase and decrease font size of text content in a div dynamically using jquery. DEMO DOWNLOAD Op...



This tutorial explains how to increase and decrease font size of text content in a div dynamically using jquery.


Open notepad, add below code and save it as an html file.

<html>
<head>
<link href='http://fonts.googleapis.com/css?family=Lato' rel='stylesheet' type='text/css'>
<style type="text/css">
 #content{
 font-family: 'Lato', sans-serif;
 text-align:justify;
 font-size:14px;
 }  
</style>
<script src="http://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
  $(document).ready(function() { 
  $('#incfont').click(function(){    
        curSize= parseInt($('#content').css('font-size')) + 2;
  if(curSize<=20)
        $('#content').css('font-size', curSize);
        });  
  $('#decfont').click(function(){    
        curSize= parseInt($('#content').css('font-size')) - 2;
  if(curSize>=12)
        $('#content').css('font-size', curSize);
        }); 
 });
</script>
</head>
<body>
<div style="background-color:gray;width:700px;height:400px;">
<div id="content" style="height:260px">
ProgrammingFree is a technical blog with quality articles on various programming languages with appropriate source code,screenshots and live demos.This blog contains information on several programming topics with appropriate screenshots and code. I never write a blog here on any topic, without actually implementing it myself to make sure that I am not misleading the readers of my blog. I am a beginner in writing though not in programming, so I really value your suggestions on my writing skills. Please remember this - the best place to get help for the issues you have in your own implementation is at technical forums and not on blogs. I welcome comments about technical inaccuracies you may spot, or typos - or indeed improvements you might want to offer to the code I have presented, or any other aspect of this site.  
</div>
<a href="#" id="incfont">A+</a>
<a href="#" id="decfont">A-</a>
</div>
</div>
</body>
</html>

Initially when the page loads, the font size is set to 14px. Then as the user clicks on increase or decrease links font size is increased or decreased by 2 units dynamically by using .css() method. Note that we have set an higher limit of 20px and lower limit of 14px for the text content. Check out the demo to see how it works.




If you think this article and other information on this website is useful to you, please keep yourself subscribed via email or other social networking sites to be notified whenever more useful articles are posted here. Thanks for reading!

Subscribe to GET LATEST ARTICLES!


Related

Jquery 2115828486956174364

Post a Comment

  1. how to put a default but example simple A

    ReplyDelete
  2. best rice cooker that might be there on your television because of which

    ReplyDelete
  3. Greetings! I simply want to offer huge thumbs up for the great stuff you have got here on this post. It looks perfect and I agreed with the topics you just said. Thanks for the share. But if you guys want Best Graphic Design Agency in India than contact us.

    ReplyDelete
  4. Hey admin

    What a Great article keep it up with awesome stuff like this.

    You have clearly mentioned all the things and guyz if you want Love Marriage Vashikaran Specialist Baba ji Mumbai than visit our blog as well thnks.

    ReplyDelete
  5. Really impressed! Everything is very open and very clear clarification of issues. It contains truly facts. Your website is very valuable. Thanks for sharing 먹튀검증

    ReplyDelete
  6. blog always contains new and exciting information Someone To Write My Essay For Me and reading it feel like this blog really has all of these qualities that make it a blog.

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete
  8. One of the most effective ways to learn programming is by engaging with online communities. Websites like Stack Overflow, Reddit, and GitHub are bustling with experienced developers willing to share their knowledge and help newcomers. Participating in forums, joining coding subreddits, and contributing to open-source projects can accelerate your learning and provide invaluable insights. These communities also offer networking opportunities, allowing you to connect with like-minded individuals and potential mentors.
    experienced family lawyers
    loudoun traffic lawyer

    ReplyDelete
  9. This article’s explanation of adjusting font sizes with jQuery is super handy! It reminds me of playing bad parenting

    ReplyDelete
  10. This article really simplifies working with font size adjustments in jQuery. Thanks for breaking it down so clearly It feels like navigating through code could be as smooth as playing Slope Game online. Seriously that game is a fun way to unwind after a coding session. Appreciate the insights and practical tips.

    ReplyDelete
  11. This comment has been removed by the author.

    ReplyDelete

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

SUBSCRIBE


Hot in weekRecentComments

Recent

Spring Security 4 for Spring MVC using Spring Data JPA and Spring Boot

I have been writing a series of tutorials on using Spring Security 4 in Spring MVC application starting from the basic in-memory authentication. In this post, I am writing a step by ste...

Spring Security JDBC Authentication with Password Encryption

I published a basic level tutorial on how to implement JDBC Authentication and Authorization using Spring Security last week. There are few best practices to be followed while implementing secur...

Spring Security 4 - Simple JDBC Authentication and Authorization

In one of my articles, I explained with a simple example on how to secure a Spring MVC application using Spring Security and with Spring Boot for setup. I am going to extend the same example to ...

Java String Split with Pipe Character Not Working - Solution

If you are working on Java, you might have run into this issue when you try to split a string based on a pipe character ("|"). It simply won't work. Split method in Java takes regex as an argumen...

Comments

waqas blog:


business help sport business grow for need help thanks for sharing post
ECM online shop
ECMonlineshop

We Care India:

You're really doing your best work here, keep it Keyword!

Ninja:

A very well-written and thought-provoking post. It offers practical tips and a fresh perspective on the topic5-16-2025

Jack Harrison:

Great insights on 2015 web design trends! It's amazing to see how responsive layouts and flat design started shaping modern user experiences. Looking forward to how these foundations continue evol...

item