This is my problem:
We have 5 input fields with the same class name, for example class="inputfield"
. By default, when the page is loaded, you only see the first. Next to the field you have a button to show the second field. When you click on it, the function showNext()
is used and you will see the second field with next to it again a button to show the 3rd field etc...
What do I want to do? I have to get the last visible input field with class="inputfield"
.
I've already found the function last() and :visible
, but when I click on the button to show the next input field, the first is still the last because I don't know how to refresh my code.
What I want to do is, every time the function showNext
is called, I need to run my code so I alway have the last visible input field. I can't add code in showNext()
so I need a listener
and my own code to select the last visible input field.
With my code I want to add a value in the input field when the user clicks on another button that I will display. But I always need to add it to the last visible input field, that's why I need to know what the last visible field is...
Extra info: The non visible fields are already in the code with display:none. What I tried is:
- when I only use the
$(".inputfield").last()
I get the last field, but the invisible one... - with
$(".inputfield:visible")
it's always the first that is "selected". Even if the second is now visible
Is this possible?
Printscreen of my problem: I select it with
$(".inputfield:visible").last().css("border", "2px solid #990000");
Edit: I think I found a way around for my problem so I always have the last visible field. Tnx for the help.