I have the following html:
<div class="active_string">
<input type="text" class="answer" /><div class="images"><img src="/images/myImage.png" alt="" /></div>
<a href="" class="check_quest" id="1">Click me</a>
</div>
<div class="active_string">
<input type="text" class="answer" /><div class="images"><img src="/images/myImage.png" alt="" /></div>
<a href="" class="check_quest" id="2">Click me</a>
</div>
For every click on check_quest I want to get value of a corresponding input. How can I do it using query. I`ve tried the following:
$(this).prev().prev().text()
but this one and other combinations of prev text() and val are not showing the text Ive put into that textfield.
$('. sys'). find('input[type=text],select').
Answer: Use the jQuery val() Method You can simply use the jQuery val() method to get the value in an input text box. Try out the following example by entering something in the text input box and then click the "Show Value" button, it will display the result in an alert dialog box.
prev( [selector ] )Returns: jQuery. Description: Get the immediately preceding sibling of each element in the set of matched elements. If a selector is provided, it retrieves the previous sibling only if it matches that selector.
I think
$(this).parent().find('input').val();
would be the best way to go.
Have you tried $(this).prev('input')
?
EDIT:
I mean: $(this).prevAll('input').val()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With