{"id":1179,"date":"2012-09-16T08:38:41","date_gmt":"2012-09-16T08:38:41","guid":{"rendered":"https:\/\/theextremewebdesigns.com\/blog\/?p=1179"},"modified":"2012-09-16T08:38:41","modified_gmt":"2012-09-16T08:38:41","slug":"jquery-get-title-of-div-image-or-any-element-when-button-is-clicked","status":"publish","type":"post","link":"https:\/\/theextremewebdesigns.com\/blog\/jquery-get-title-of-div-image-or-any-element-when-button-is-clicked\/","title":{"rendered":"jQuery Get Title of Div, Image or any element when button is clicked"},"content":{"rendered":"<p>If you ever wondered how to get \/ find title of Div, Image or any element when button is clicked, using jQuery, then worry no more. In this article, I am going to show with examples, how easy it is to <em><strong>get the title of an image, a div or any other element using jQuery<\/strong><\/em>. Read on to find out more.<!--more--><\/p>\n<h2>jQuery Get Title of Div, Image or any element when button is clicked<\/h2>\n<div class=\"make_demo\">\r\n\r\n\t<form action=\"https:\/\/theextremewebdesigns.com\/blog\/wp-content\/themes\/ewd_blog_2017\/try_demo.php?post_id=1179\" method=\"post\" name=\"form1\" target=\"_blank\" id=\"form1\">\r\n\r\n\r\n\t<input type=\"hidden\" name=\"shortcode_content\" id=\"shortcode_content\" value=\"\" \/>\r\n\r\n        <div class=\"try_demo_btn_container\">\r\n\r\n\r\n            <button type=\"submit\" name=\"sbt_make_demo\" id=\"sbt_make_demo\" class=\"btn-primary btn-try-demo\">\r\n                Try Demo\r\n            <\/button>\r\n\r\n\r\n        <\/div><!-- .try_demo_btn_container -->\r\n\r\n    <\/form>\r\n    <\/div>\r\n    \n<p>Let&#8217;s assume that we have a div with ID &#8220;my_div&#8221; and we want to find the title of this div and alert it when a button is clicked. Here is how we use <em><strong>jQuery to get div title<\/strong><\/em>.<\/p>\n<h3>Example: Full source code to get image title, div title or title of any element when button is clicked using jQuery<\/h3>\n<pre class=\"lang:xhtml decode:true\">&lt;html&gt;\n&lt;head&gt;\n&lt;title&gt;jQuery Get Title of Div, Image, any element when button is clicked&lt;\/title&gt;\n&lt;script type=\"text\/javascript\" src=\"js\/jquery-1.8.2.min.js\"&gt;&lt;\/script&gt;\n&lt;\/head&gt;\n\n&lt;body&gt;\n\n&lt;div id=\"my_div\" title=\"My DIV title\"&gt;This is my existing div.&lt;\/div&gt;\n\n&lt;input type=\"submit\" name=\"sbt_get_title\" id=\"sbt_get_title\" value=\"Get Div Title\"&gt;\n\n&lt;script type=\"text\/javascript\"&gt;\n\n$('#sbt_get_title').on(\"click\", function(){\n\nvar title = $('#my_div').attr('title');\n\nalert( 'Div Title is: '+ title );\n\n});\n\n&lt;\/script&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/pre>\n<p>Run the code, click on the button to instantly alert the div title. You can simply change the selector in the jQuery code and replace it with an image&#8217;s ID or class to alert it&#8217;s corresponding title. You can apply the same procedure to find title of a div, image or any other element.<\/p>\n<div class=\"make_demo\">\r\n\r\n\t<form action=\"https:\/\/theextremewebdesigns.com\/blog\/wp-content\/themes\/ewd_blog_2017\/try_demo.php?post_id=1179\" method=\"post\" name=\"form1\" target=\"_blank\" id=\"form1\">\r\n\r\n\r\n\t<input type=\"hidden\" name=\"shortcode_content\" id=\"shortcode_content\" value=\"\" \/>\r\n\r\n        <div class=\"try_demo_btn_container\">\r\n\r\n\r\n            <button type=\"submit\" name=\"sbt_make_demo\" id=\"sbt_make_demo\" class=\"btn-primary btn-try-demo\">\r\n                Try Demo\r\n            <\/button>\r\n\r\n\r\n        <\/div><!-- .try_demo_btn_container -->\r\n\r\n    <\/form>\r\n    <\/div>\r\n    \n<h5>Easy?<\/h5>\n<p>Do you know of any other ways to <em><strong>find \/ get Title of Div, Image or any element when button is clicked<\/strong><\/em>? Feel free to suggest by commenting below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you ever wondered how to get \/ find title of Div, Image or any element when button is clicked, using jQuery, then worry no more. In this article, I am going to show with examples, how easy it is to get the title of an image, a div or any other element using jQuery. [&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,42,41],"class_list":["post-1179","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-demos-2","tag-jquery-tips"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/paBnQX-j1","jetpack_sharing_enabled":true,"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/1179","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=1179"}],"version-history":[{"count":0,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/1179\/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=1179"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/categories?post=1179"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/tags?post=1179"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}