error77
asked on
Reversing jQuery code function
Hi all,
I have the following code which when used in a link goes forward to the next link ... so I'm basically using it to do the function of a next button.
What I need to do is to create a reverse version so I can use it as a Back button.
Here is the code:
<script>
$("a.mytrigger").click(fun ction(e){
var index = $(this).attr("href").subst r(5);
$('#navigation li:nth-child('+parseInt(in dex)+') a').click();
e.preventDefault();
});
</script>
Please see this link... http://tympanus.net/Tutori als/FancyS lidingForm /
If you click on the tabs at the bottom ... The next tab is the code above what I need to do it the reverse ... in other words go back.
THanks
I have the following code which when used in a link goes forward to the next link ... so I'm basically using it to do the function of a next button.
What I need to do is to create a reverse version so I can use it as a Back button.
Here is the code:
<script>
$("a.mytrigger").click(fun
var index = $(this).attr("href").subst
$('#navigation li:nth-child('+parseInt(in
e.preventDefault();
});
</script>
Please see this link... http://tympanus.net/Tutori
If you click on the tabs at the bottom ... The next tab is the code above what I need to do it the reverse ... in other words go back.
THanks
You mean
<script>
$("a.mytrigger").click(fun ction(e){
var index = parseInt($(this).attr("hre f").substr (5));
if ($(this).attr("id")==="nex t") {
index++;
if (index>maxIndex) index=0; //wrap
}
else {
index--;
if (index<0) index=maxIndex; //wrap
}
$('#navigation li:nth-child('+index+') a').click();
e.preventDefault();
});
</script>
<script>
$("a.mytrigger").click(fun
var index = parseInt($(this).attr("hre
if ($(this).attr("id")==="nex
index++;
if (index>maxIndex) index=0; //wrap
}
else {
index--;
if (index<0) index=maxIndex; //wrap
}
$('#navigation li:nth-child('+index+') a').click();
e.preventDefault();
});
</script>
ASKER
So if I am using this:
$("a.mytrigger").click(fun ction(e){
var index = $(this).attr("href").subst r(5);
$('#navigation li:nth-child('+parseInt(in dex)+') a').click();
e.preventDefault();
});
to go foward ... what's the script to go back?
Here's my currebt one ..
$("a.back_mytrigger").clic k(function (e){
var index = $(this).attr("href").subst r(5);
$('#navigation li:nth-child('+parseInt(in dex)-') a').click();
e.preventDefault();
});
What do I change in it?
Thanks
$("a.mytrigger").click(fun
var index = $(this).attr("href").subst
$('#navigation li:nth-child('+parseInt(in
e.preventDefault();
});
to go foward ... what's the script to go back?
Here's my currebt one ..
$("a.back_mytrigger").clic
var index = $(this).attr("href").subst
$('#navigation li:nth-child('+parseInt(in
e.preventDefault();
});
What do I change in it?
Thanks
Mine should do both depending on the ID
They both have class="mytrigger" and next has id="next" - the other can have any ID
They both have class="mytrigger" and next has id="next" - the other can have any ID
ASKER
For the NEXT... would I be able to change it to a class because I need to use several next button as I have multiple steps ?
Yes
ASKER
OK, I'm trying the code but cannot get it to work...
This is what I'm doing to trigger the buttons:
<a href="#step2" class="mytrigger>Go Back</a>
<a href="#step3" class="mytrigger next>Go Next</a>
is this the right way?
This is what I'm doing to trigger the buttons:
<a href="#step2" class="mytrigger>Go Back</a>
<a href="#step3" class="mytrigger next>Go Next</a>
is this the right way?
I'll look in a little while
ASKER
Thanks a lot!
If your html is this
<a href="#step2" class="mytrigger">Go Back</a>
<a href="#step3" class="mytrigger">Go Next</a>
and your code (nth-child even counts from 1)
<script>
$("a.mytrigger").click(fun ction(e){
var index = $(this).attr("href").subst r(5);
$('#navigation li:nth-child('+parseInt(in dex)+') a').click();
e.preventDefault();
});
</script>
then I do not see what you need to change... Like chaituu said
Perhaps you can show your page and tell us what happens when you run the code?
<a href="#step2" class="mytrigger">Go Back</a>
<a href="#step3" class="mytrigger">Go Next</a>
and your code (nth-child even counts from 1)
<script>
$("a.mytrigger").click(fun
var index = $(this).attr("href").subst
$('#navigation li:nth-child('+parseInt(in
e.preventDefault();
});
</script>
then I do not see what you need to change... Like chaituu said
Perhaps you can show your page and tell us what happens when you run the code?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Recommend points awarded to mplungjan
We will first need to see it working and then likely a split with chaituu since I was barking up the wrong tree with my first post(s)
ASKER
Sorry that didn't work :o/
Can't it be modified so I can tell it - Go to a specific ID and have it go there?
Can't it be modified so I can tell it - Go to a specific ID and have it go there?
ASKER
OK That worked. My mistake :) Thanks a lot!
if you want to trigger the function already existed;
use trigger function.
$("a.mytrigger").trigger('