{"id":816,"date":"2012-06-07T05:05:26","date_gmt":"2012-06-07T05:05:26","guid":{"rendered":"https:\/\/theextremewebdesigns.com\/blog\/?p=816"},"modified":"2012-06-07T05:05:26","modified_gmt":"2012-06-07T05:05:26","slug":"jquery-get-textarea-id-examples","status":"publish","type":"post","link":"https:\/\/theextremewebdesigns.com\/blog\/jquery-get-textarea-id-examples\/","title":{"rendered":"jQuery Get Textarea ID Examples"},"content":{"rendered":"<p>Did you ever feel the need to use<strong> jquery to Get Textarea ID<\/strong>? In this article, I am going to share with you a very simple way to <strong>get textarea ID using jQuery<\/strong>. Actual code is just 1 line, so it&#8217;s super easy to follow and implement.<!--more--><\/p>\n<h2>How to use jQuery to Get Textarea ID<\/h2>\n<p>Let&#8217;s assume that you have 3 textareas with ID &#8220;comments&#8221;, &#8220;skills&#8221; &amp; &#8220;description&#8221;. The HTML code for the textareaes would be:<\/p>\n<pre class=\"lang:xhtml decode:true\">&lt;textarea name=\"comments\" id=\"comments\"&gt;&lt;\/textarea&gt;\n\n&lt;textarea name=\"skills\" id=\"skills\"&gt;&lt;\/textarea&gt;\n\n&lt;textarea name=\"description\" id=\"description\"&gt;&lt;\/textarea&gt;<\/pre>\n<p>Now you want to get the ID of the textarea whose value has been changed. You can do it in the following manner:<\/p>\n<h3>Example 1: Get Textarea ID on change<\/h3>\n<pre class=\"lang:js decode:true\">&lt;script type=\"text\/javascript\"&gt;\n\n$(document).ready(function() {\n\n$('input[type=\"textarea\"]').change(function(){\nvar id = $(this).attr('id');\nalert(id);\n});\n\n});\n\n&lt;\/script&gt;<\/pre>\n<p>When you run the above example, you will see the 3 input textareas. Simply enter anything in any of these textareas and click outside it so that the textarea loses focus. As soon as you do that, you will see the JavaScript alert that shows you the ID of the textarea in which you just made the change.<\/p>\n<h3>Example 2 &#8211;\u00a0Get Textarea ID using name attribute<\/h3>\n<p>Let&#8217;s take the above example as the basis for this example. Let&#8217;s assume that you have only the name of the textarea and now you want to get the textarea ID using just the name. For illustration purposes, let&#8217;s assume that you want to get the ID of the &#8220;description&#8221; textarea using just it&#8217;s name. You can do it as below:<\/p>\n<pre class=\"lang:js decode:true\">&lt;script type=\"text\/javascript\"&gt;\n\n$(document).ready(function() {\n\nvar id = ( $('input[name=\"description\"]').attr('id') );\n\nalert(id);\n\n});\n\n&lt;\/script&gt;<\/pre>\n<p>In the above example, when you run the page, you will receive a JavaScript alert box that gives you the ID of the &#8220;description&#8221; textarea. Note that we are using the &#8220;name&#8221; attribute of the &#8220;description&#8221; textarea in order to get it&#8217;s ID.<\/p>\n<h3>Example 3 &#8211;\u00a0Get Textarea ID using class<\/h3>\n<p>Let&#8217;s assume that you have applied a class of &#8220;my_textarea&#8221; to all the textareas. You can now find out the ID of the textarea whose value has been changed using the class like so:<\/p>\n<pre class=\"lang:js decode:true\">&lt;script type=\"text\/javascript\"&gt;\n\n$(document).ready(function() {\n\n$('.my_textarea').change(function(){\nvar id = $(this).attr('id');\nalert(id);\n});\n\n});\n\n&lt;\/script&gt;<\/pre>\n<p>When you run the above example, you will see the 3 input textareas. Simply enter anything in any of them and click outside the textarea so that it loses focus. As soon as you do that, you will see the JavaScript alert that shows you the ID of the textarea in which you just made the change.<\/p>\n<p><strong>That&#8217;s it!<\/strong><\/p>\n<p>Do you know of any other ways to <strong>get textarea ID using jQuery<\/strong>? Feel free to suggest by commenting below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Did you ever feel the need to use jquery to Get Textarea ID? In this article, I am going to share with you a very simple way to get textarea ID using jQuery. Actual code is just 1 line, so it&#8217;s super easy to follow and implement.<\/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":[41],"class_list":["post-816","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-jquery-tips-and-tricks","category-tips-and-tricks","tag-jquery-tips"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/paBnQX-da","jetpack_sharing_enabled":true,"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/816","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=816"}],"version-history":[{"count":0,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/816\/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=816"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/categories?post=816"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/tags?post=816"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}