javascript - Replacing an element by using jQuery -
javascript - Replacing an element by using jQuery -
i have html output in paging section this;
<p> <strong class="active">1</strong> <a href="http://localhost/project/report_nc/search_now/1">2</a> <a href="http://localhost/project/report_nc/search_now/2">3</a> <a href="http://localhost/project/report_nc/search_now/1">next »</a> </p> now need add together attribute "onclick" using jquery. unfortunately "onclick" attribute cannot set jquery. @ same time came thought : taking single anchor tag (i.e. <a href="http://localhost/project/report_nc/search_now/2"></a>) , replace new anchor tag (i.e. <a href="javascript:void(0)" onclick="myfunction(2)"></a>).
how jquery? thought post form while clicking on paging links.
solved !
thank kind responses......i guess there minor error in code; looking through code posted umesh noticed "onclick"...yes using "onclick" instead of "onclick". has worked in ff , work in ie too.
value of anchor can used pass value function myfunction. if anchor doesn't contain value, don't anything.
working test code below:
<html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function(){ // utilize proper anchor selector on page $("a").each(function(){ var no=$(this).html(); if(!isnan(parseint(no))){ $(this).attr("onclick","myfunction("+no+")"); $(this).attr("href","javascript:void(0)"); } }); }); </script> </head> <body> <p> <strong class="active">1</strong>& nbsp; <a href="http://localhost/project/report_nc/search_now/1">2</a> <a href="http://localhost/project/report_nc/search_now/2">3</a> <a href="http://localhost/project/report_nc/search_now/1">next »</a> </p> </body> </html> javascript jquery replace
Comments
Post a Comment