{"id":134,"date":"2016-08-28T17:23:00","date_gmt":"2016-08-28T17:23:00","guid":{"rendered":"http:\/\/www.java2blog.com\/?p=134"},"modified":"2023-11-25T16:23:28","modified_gmt":"2023-11-25T10:53:28","slug":"jquery-text-method-example","status":"publish","type":"post","link":"https:\/\/java2blog.com\/jquery-text-method-example\/","title":{"rendered":"jQuery text() method example"},"content":{"rendered":"<div dir=\"ltr\" style=\"text-align: left;\">In this post, \u00a0we are going to see jQuery text method example.<\/p>\n<div>text method is used to get text of all matched elements and text(&#8216;new text&#8217;) is used to set text for all matched elements.<\/div>\n<div>Syntax for text() :<\/div>\n<div>\n<pre name=\"code\">$(\"selectors\").text() \nExample :\n$(\"div\").text();<\/pre>\n<\/div>\n<div>Syntax for text(&#8216;new text&#8217;) :<\/div>\n<div>\n<pre name=\"code\">$(\"selectors\").text('new text')\nExample:\n $(\"div\").text('this text is being set by text method');<\/pre>\n<\/div>\n<div><\/div>\n<div>Let&#8217;s understand with the help of example:<\/div>\n<pre class=\"xml \" data-blogger-escaped-name=\"code\">\n\n\n  <title>Jquery text method example <\/title>\n  <script src=\"http:\/\/code.jquery.com\/jquery-2.2.3.min.js\"><\/script>\n\n<h2>Jquery text method example<\/h2>\n<style>\n.blackBorder{\n        border:4px dotted black;\n<\/style>\n<script type=\"text\/javascript\">\n   $(document).ready(function(){\n      $(\"#textButton\").click(function(){\n         alert($(\"div\").text()) ;\n      });\n$(\"#setTextButton\").click(function(){\n         $(\"div\").text('this text is being set by text() method');\n      });\n$(\"#reset\").click(function(){\n         location.reload();\n   });\n });\n\n<\/script>\n\n  <button id=\"textButton\">Using text<\/button>\n  <button id=\"setTextButton\">Using text('new text') <\/button>\n<button id=\"reset\">Reset<\/button>\n<br>\n<div class=\"blackBorder\">\n Hello world from java2blog!!!!\n   <\/div>\n<br>\n<div class=\"blackBorder\">\n Welcome to JQuery.\n  <\/div>\n\n<\/pre>\n<p>Live demo: <a href=\"http:\/\/jsbin.com\/gipesapote\/embed?html,output\" target=\"_blank\" rel=\"noopener\">Jquery text method example on jsbin.com<\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this post, \u00a0we are going to see jQuery text method example. text method is used to get text of all matched elements and text(&#8216;new text&#8217;) is used to set text for all matched elements. Syntax for text() : $(&#8220;selectors&#8221;).text() Example : $(&#8220;div&#8221;).text(); Syntax for text(&#8216;new text&#8217;) : $(&#8220;selectors&#8221;).text(&#8216;new text&#8217;) Example: $(&#8220;div&#8221;).text(&#8216;this text is being [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_mi_skip_tracking":false},"categories":[42,43],"tags":[],"_links":{"self":[{"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/posts\/134"}],"collection":[{"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/comments?post=134"}],"version-history":[{"count":1,"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/posts\/134\/revisions"}],"predecessor-version":[{"id":25867,"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/posts\/134\/revisions\/25867"}],"wp:attachment":[{"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/media?parent=134"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/categories?post=134"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/tags?post=134"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}