My problem is that the else section here doesn’t seem to work.
I already surfed the web for a solution and even though there are very many questions exactly like mine, the answer always seems to be different.
This is the button I click on
<input type="submit" value="4">
I also have a button like this:
<input type="submit" id="b1" value="Back">
My Aim is to find out if the button with an ID was clicked or not.
var specify = "";
var prevpos = 0;
$('input[type=submit]').click(function(){
specify = $(this).attr('value');
if($(this).attr('id').substring(0,1) == "b")
{
$("html, body").animate({scrollTop: prevpos}, 777);
$(".right").animate({opacity: 0.0}, 200);
$(".left").animate({opacity: 1.0}, 200);
// more stuff here
}
else
{
$("html, body").animate({scrollTop: prevpos}, 777);
// more stuff here
}
});
As always, any help is greatly appreciated!
The problem with your code is because when you click the button without an
idyou are callingsubstr()on a null, which will cause errors.Try this instead:
Example fiddle