javascript - Replacing an element by using jQuery -



javascript - Replacing an element by using jQuery -

i have html output in paging section this;

<p>&nbsp;<strong class="active">1</strong>&nbsp;<a href="http://localhost/project/report_nc/search_now/1">2</a>&nbsp;<a href="http://localhost/project/report_nc/search_now/2">3</a>&nbsp;<a href="http://localhost/project/report_nc/search_now/1">next »</a>&nbsp;</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>&nbsp; <strong class="active">1</strong>& nbsp; <a href="http://localhost/project/report_nc/search_now/1">2</a>&nbsp; <a href="http://localhost/project/report_nc/search_now/2">3</a>&nbsp; <a href="http://localhost/project/report_nc/search_now/1">next »</a>&nbsp; </p> </body> </html>

javascript jquery replace

Comments

Popular posts from this blog

delphi - blogger via idHTTP : error 400 bad request -

c++ - compiler errors when initializing EXPECT_CALL with function which has program_options::variables_map as parameter -

How do I check if an insert was successful with MySQLdb in Python? -