John John - 6 months ago 32
Javascript Question

Replace url parameter with jquery

I got 3 Tabs Visit, History, Files. The navigation is like this

<a id="nav_visit" href="#tab_visit" data-g-toggle="tab">Visit</a>
<a id="nav_history" href="#tab_history" data-g-toggle="tab">Visit</a>
<a id="nav_files" href="#tab_files" data-g-toggle="tab">Visit</a>

Also i got a link to edit some stuff in the tabs like this

<div><a id="editwithtab" href="edit?id=<?php echo $id;?>&tab=tab_visit">EDIT</a></div>

When you click one of the li Tabs it adds the Tab ID to a hidden field for some other reasons.

$(document).on('click', '#nav_visit', function() {
$(document).on('click', '#nav_history', function() {
//$('#editwithtab').replace("tab=tab_visit", "tab=tab_history");
//tab= tab_visit or tab_history(in this case it wont matter) or tab_files
$(document).on('click', '#nav_files', function() {

What I want it to do is also change the parameter "tab=" in the edit link so that it can redirect to the edit page with the same tab open.

I found other posts about this replace but none had a php echo in the link.

Any help?


You can try this:

$('#editwithtab').attr('href', function(i, href) {
    return href.split("&")[0] + "&tab=tab_history"; 

I hope this will help.