document.getElementById('div1').innerHTML = 'My Text';
$("#div1").html("My Text");
document.getElementById('div1').innerText = '<b>My Text</b>';
$("#div1").text("My Text");
<html> <head> <title>ThaiCreate.Com jQuery Tutorials</title> <script type="text/javascript" src="jquery-1.6.4.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("#btn1").click(function(){ $("p").html($("#txt1").val()); $("#div1").text($("#txt1").val()); }); }); </script> </head> <body> <p></p> <div id="div1"></div> <input type="text" id="txt1"> <input type="button" id="btn1" value="Click"> </body> </html>
<html> <head> <title>ThaiCreate.Com jQuery Tutorials</title> <script type="text/javascript" src="jquery-1.6.4.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("#btn1").click(function(){ alert($("p").html()); alert($("p").text()); }); }); </script> </head> <body> <p><b>ThaiCreate.Com</b></p> <input type="button" id="btn1" value="Click"> </body> </html>
<html> <head> <title>ThaiCreate.Com jQuery Tutorials</title> <script type="text/javascript" src="jquery-1.6.4.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("#btn1").click(function(){ $("p").append($("#txt1").val()); $("#div1").append("<b>"+$("#txt1").val()+"</b>"); }); }); </script> </head> <body> <p><b>Welcome to... </b></p> <div id="div1">Welcome to ...</div> <input type="text" id="txt1"> <input type="button" id="btn1" value="Click"> </body> </html>
<html> <head> <title>ThaiCreate.Com jQuery Tutorials</title> <script type="text/javascript" src="jquery-1.6.4.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("#btn1").click(function(){ $("p").prepend($("#txt1").val()); $("#div1").prepend("<b>"+$("#txt1").val()+"</b>"); }); }); </script> </head> <body> <p><b>Welcome to... </b></p> <div id="div1">Welcome to ...</div> <input type="text" id="txt1"> <input type="button" id="btn1" value="Click"> </body> </html>
<html> <head> <title>ThaiCreate.Com jQuery Tutorials</title> <script type="text/javascript" src="jquery-1.6.4.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("#btn1").click(function(){ $("p").after($("#txt1").val()); $("#div1").after("<b>"+$("#txt1").val()+"</b>"); }); }); </script> </head> <body> <p><b>Welcome to... </b></p> <div id="div1">Welcome to ...</div> <input type="text" id="txt1"> <input type="button" id="btn1" value="Click"> </body> </html>
<html> <head> <title>ThaiCreate.Com jQuery Tutorials</title> <script type="text/javascript" src="jquery-1.6.4.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("#btn1").click(function(){ $("p").before($("#txt1").val()); $("#div1").before("<b>"+$("#txt1").val()+"</b>"); }); }); </script> </head> <body> <p><b>Welcome to... </b></p> <div id="div1">Welcome to ...</div> <input type="text" id="txt1"> <input type="button" id="btn1" value="Click"> </body> </html>
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท