JQuery Set Font Size

From CoderLearner
Jump to: navigation, search

jQuery Set the font size

Set Font Size uses css() function.

Syntax

$("p").css("font-size","24");
$("div.kk33").css("font-size","10");

Note

Set font size for class attribute or just HTML elements.

Example 1

<!DOCTYPE html>
<html>
	<head>
		<title>Change Font Size</title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<script type="text/javascript" src="jquery.min.js">
		</script>
		<script>
			$(document).ready(function(){
				$("p").css("font-size","24px");
				$("div.kk33").css("font-size","10px");
			});
		</script>
	</head>
	<body>
                <p>All of the people are very happy.</p>
		<p class="k33">Great people like to say great things.</p>
		<div class="kk33">Nothing can be changed right now!</div>
	</body>
</html>


Example 2

<!DOCTYPE html>
<html>
   <head>
      <title>First Project</title>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <script 
         type="text/javascript" 
         src="/lib/jquery-1.7.2.min.js">				 
      </script>
      <script language="javascript">
         $(document).ready(function(){
            $('#changeit').click(function(){
               var sel_value = $('select[name="fontsize"] option:selected').val();
               $('div p').css('font-size',sel_value+'px');
            });
         });
      </script>
   </head>
   <body>
      <select name="fontsize">
         <option value="12">12</option>
         <option value="15">15</option>
         <option value="20">20</option>
         <option value="30">30</option>
      </select>
      <button id="changeit">Change It</button>
      <div>
         <p>Learn how to use PHP</p>
         <p>King and Queen are very healthy.</p>
      </div>
   </body>
</html>

Try It

<seo metagenerator="jquery tutorial" title="Jquery/Ajax" metakeywords="jquery greater,jquery gt, jquery lt, less then, odd jquery,jquery find element, even jquery,jquery event, jquery mouse click, jquery double click, jquery hover, jquery string, jquery array, jquery button, jquery attriubtes" metadescription="jquery button, jquery attriubte, jquery example, jquery tutorial, jquery sample"/>