Tags contain content operations
Use javascript operations:
dvnode.innerHTML Get the information contained in the div
dvnode.innerHTML = XXX; Set the content contained in the div
Note: innerHTML is not a w3c standard technology , many browsers only support it
Use jquery operation:
<!DOCTYPE html> <html> <head> <title>php.cn</title> <meta charset="utf-8" /> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script> <script> function f1(){ alert($('div').html()); alert($('div').text()); } function f2(){ $('div').text("这里是php中文网"); } </script> </head> <body> <div>欢迎 <p>大家 <span>学习jQuery</span></p></div> <input type="button" value="获取" onclick="f1()" /> <input type="button" value="设置" onclick="f2()" /> </body> </html>
##① Get content