I have some js (show/hide pretty standard I guess):
<script>
function showTransactions(transactions){
$('.steps').hide()
$('#' + transactions).show();
}
</script>
and some html:
<p><a href="#"onClick="showTransactions('hidden3');return false;">Edit</a></p>
<div id="hidden3" class="steps" style="display: none;">
Now this works great when I click the link, it shows it. Easy. How can I get the js to refresh to the current step? I have steps hidden1, hidden2, hidden3, and hidden4. The default starting position is hidden1 so on refresh it will display hidden1 instead of hidden3 if that’s where you were on refresh.
Also, I need to direct users to a specific step on some instances via a url link. I tried page_url#hidden4 but that doesn’t work. I need to be able to tell it to display hidden4 in that link instead of the default first step.
Two main things are wrong with your code:
onclickinline JavaScript. Don’t do that. That’s not the way JavaScript/HTML integration is written anymore. jQuery has event handlers to catch click events for you. Always keep HTML and JavaScript 100% separate.CSS:
HTML
JavaScript
The above makes use of the fact that the
document.location.hash, a page-internal<a href>and jQuery’s ID selector all use the same syntax.As long as you just want to transport a single bit of information in the hash, this is all you need.