2

I'm creating wizard using javascript and jquery and I'm facing a problem I need to move the wizard from 1st tab to second tab after the successful completion of the first tab and its not working my current code is like given below

<div main>
<div id="tab1">
.......
</div>
<div id="tab2">
.....
</div>
</div>

and I tried the following code for navigation on button click

 window.location.href = "#tab2";

but its not working how can I solve this ???

1 Answer 1

1

you can directly use location.hash in place of window.location.href , as:

location.hash = "#tab2";

try and create a function as:

function scrollToHash(hashname) {
    location.hash = "#" + hashname;
}

and use it while navigating between tabs.

Sign up to request clarification or add additional context in comments.

4 Comments

but its not working for me when I click the button the url seems to be changed but the page dose't change I used bootstrap.js for creating. Is that a problem
@Alen, I can n't say that bootstrap.js would be causing problem in that scenario, but you can do one thing to check it. try and hit url with hash directly from addressbar of browser, if it still not working, then I can assure you that you are trying to hit an invalid hash.
You are right I used an invalid hash but what will be the correct hash then if i tried the #tab2 in a link it work perfectley
@Alen, by invalid hash, I mean, you will be passing the incorrect id in hash, but as you said it works when you click on the link directly, then there may be some other issue in the code. can you post that perticular code?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.