1 2 3 4 5 |
$("selectors").text() Example : $("div").text(); |
1 2 3 4 5 |
$("selectors").text('new text') Example: $("div").text('this text is being set by text method'); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
<!doctype> <html> <head> <title>Jquery text method example </title> <script src="http://code.jquery.com/jquery-2.2.3.min.js"></script> </head> <h2>Jquery text method example</h2> <style> .blackBorder{ border:4px dotted black; </style> <script type="text/javascript"> $(document).ready(function(){ $("#textButton").click(function(){ alert($("div").text()) ; }); $("#setTextButton").click(function(){ $("div").text('this text is being set by text() method'); }); $("#reset").click(function(){ location.reload(); }); }); </script> <body> <button id="textButton">Using text</button> <button id="setTextButton">Using text('new text') </button> <button id="reset">Reset</button> <br /> <div class='blackBorder'> Hello world from java2blog!!!! </div> <br/> <div class='blackBorder' > Welcome to JQuery. </div> </body> </html> |
Live demo: Jquery text method example on jsbin.com