0

I have table data(td) as hyperlink(href). If i click the td then its redirect. Now i want to change the URL only not the redirection.I use the following code:

 <td><a href="<?php echo base_url() . "index.php/" .$Users->UserPcKey; ?>">
<?php echo $Users->UserPcKey; ?></a></td>

Thanks .

ArK
  • 20,698
  • 67
  • 109
  • 136
SaranPHP
  • 11
  • 4

2 Answers2

0

You have to use the preventDefault function like this in JQuery, it will be more in front code than in back code for the behaviour you expect. Here the link I disable is the one with the id "myLink" :

<script>
    $('#myLink').click(function(e)
        $(this).attr("href","http://your_link.com");
    });
</script>
Nicolas D
  • 1,182
  • 18
  • 40
  • Thanks... at the mean time , what is mylink? And chay i want to change url in onclick of href. ...And also i have n number of 's in my code. – SaranPHP Apr 07 '16 at 11:37
  • I am asking while click on the href it automatically redirect. But in my code, i need the url change but not redirection. If i use above code the url change is not done. So guide me. – SaranPHP Apr 07 '16 at 11:59
  • I just edited, I think this will be good if you want just to update the url after the clic – Nicolas D Apr 07 '16 at 12:19
0

If prevent default is called, the default action of the event will not be triggered.

$(function(){
    $("#anchorId").click(function(e){
        e.preventDefault();
        $(this).attr("href","http://newlink.com");
    }); });​​​​
node_saini
  • 727
  • 1
  • 6
  • 22
  • If i use the prevent default(), then the url is not change by href. In my above code i change the id in url but dont need redirection. – SaranPHP Apr 07 '16 at 11:51
  • prevent default() will replace your base URL, change it to newlink.com so when you click on td it will redirect to newlink.com not your base url. i hope this is what you want... – node_saini Apr 07 '16 at 11:57
  • In my code the new link url changes based on the row value on each click. So how can i pre-define? – SaranPHP Apr 07 '16 at 12:07