{"id":1355,"date":"2012-10-28T03:03:23","date_gmt":"2012-10-28T03:03:23","guid":{"rendered":"https:\/\/theextremewebdesigns.com\/blog\/?p=1355"},"modified":"2012-10-28T03:03:23","modified_gmt":"2012-10-28T03:03:23","slug":"jquery-set-height-in-px-em-pt-set-div-height-set-li-height","status":"publish","type":"post","link":"https:\/\/theextremewebdesigns.com\/blog\/jquery-set-height-in-px-em-pt-set-div-height-set-li-height\/","title":{"rendered":"jQuery Set Height in px, em, pt Examples (Div Height, li Height, etc.)"},"content":{"rendered":"<p>In an earlier article, we have seen how we can get the height of an element, such as a div, li, etc. using jQuery. In this article, lets discuss how to\u00a0<em><strong>set height in px(pixels), em, pt, etc. using jQuery<\/strong><\/em> The actual code to \u00a0is just 1 line, so it&#8217;s super easy to follow along. Read on to find out more.<\/p>\n<h2><!--more-->How to Set the Height of elements using jQuery?<\/h2>\n<p>jQuery provides us with a very simple method, called height(). So the basic syntax to set height of an element would be as follows:<\/p>\n<h3>Basic Syntax to Set element height using jQuery<\/h3>\n<pre class=\"lang:js decode:true\">\/\/value represents numerical value in pixels\n$(selector).height(value);\n\n\/\/optionally you can specify the relative unit of measurement along with the value\n$(selector).height(\"valuepx\");<\/pre>\n<h3>Example 1: Set div height using div ID &#8211; Set it to 50 pixels<\/h3>\n<pre class=\"lang:js decode:true\">$('#my_div').height(50);\n\n\/\/The code below produces the same output as the above code\n$('#my_div').height(\"50px\");<\/pre>\n<h3>Example 2: Set div height using div class &#8211; Set it to 100 pixels<\/h3>\n<pre class=\"lang:js decode:true\">$('.my_div_class').height(100);<\/pre>\n<h3>Example 3: Set li height &#8211; Set it to 75 pixels<\/h3>\n<pre class=\"lang:js decode:true\">$('ul li').height(75);<\/pre>\n<h3>Example 4: Set specific li height &#8211; Set it to 18 pixels<\/h3>\n<pre class=\"lang:js decode:true\">$('li#list_item_1').height(18);\n\n$('#list_item_1').height(18);<\/pre>\n<h3>Example 5: Set paragraph height &#8211; Set it to 100 pixels<\/h3>\n<pre class=\"lang:js decode:true\">$('p').height(100);<\/pre>\n<p>If you have noticed something, all heights expressed are in pixels. What if you want to use another measurement alternative such as em, pt instead of pixels? Let&#8217;s see how we can do that.<\/p>\n<h3>Example 6: Set div height using div ID &#8211; Set it to 10 em<\/h3>\n<pre class=\"lang:js decode:true\">$('#my_div').height(\"10em\");<\/pre>\n<h3>Example 7: Set div height using div class &#8211; Set it to 1000 pt<\/h3>\n<pre class=\"lang:js decode:true\">$('.my_div_class').height(\"1000pt\");<\/pre>\n<h5>Your Turn!<\/h5>\n<p>Do you know of any other ways to <strong>set height of an element (li, div, etc.) using jQuery<\/strong>? Feel free to suggest by commenting below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In an earlier article, we have seen how we can get the height of an element, such as a div, li, etc. using jQuery. In this article, lets discuss how to\u00a0set height in px(pixels), em, pt, etc. using jQuery The actual code to \u00a0is just 1 line, so it&#8217;s super easy to follow along. Read [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":395,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[20,13],"tags":[40,41],"class_list":["post-1355","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-jquery-tips-and-tricks","category-tips-and-tricks","tag-jquery-2","tag-jquery-tips"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/paBnQX-lR","jetpack_sharing_enabled":true,"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/1355","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/comments?post=1355"}],"version-history":[{"count":0,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/1355\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/media?parent=1355"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/categories?post=1355"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/tags?post=1355"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}