jquery modify the href link and text of a tag
The following code to modify the href link of the a tag and modify the text: <script type="text/javascript" src="http:/keleyi.com/keleyi/pmedia/jquery-1.9.1.min.js"></script> Original link: <a href="http://keleyi.com" id="home_keleyi_com">柯乐义</a> Modify the href link of the a tag: $('#home_keleyi_com').attr('href','http://keleyi.com'); Modify the text: $("#home_keleyi_com").text('Keleyi Homepage'); The revised link is: <a href="http://keleyi.com" id="home_keleyi_com">柯乐义首页</a>
Here is the complete code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>jquery modification link -- Ke Leyi</title> <script type="text/javascript" src="http://keleyi.com/keleyi/pmedia/jquery-1.9.1.min.js"></script> </head> <body> jQuery modifies the href link and text of the a tag, first click the link below <br /> and then click the "Change" button, then click the link below once, pay attention to the difference between opening the page twice:<br /> <a href="http://keleyi.com/a/bjac/d863921ed93d03ff.htm" id="home_keleyi_com" target="_blank">原文</a> <input type="button" value="改变" id="gb_keleyi_com" /> <script type="text/javascript"> $("#gb_keleyi_com").bind("click",function (){ $('#home_keleyi_com').attr('href','http://keleyi.com'); $("#home_keleyi_com").text('Keleyi Homepage');}) </script> </body> </html>