0

first at all thanks for reading.

I wrote a code that suppose to search any input type text inside many the idea is search if each element inside of the contains a text, if it's then the tr will be .show() if any of the elements inside of the tr contains the text the tr will be .hide(). But i cant get the value of the input, maybe some silly mistake. So the structure could be:

   <tr>
    <td><div><div><input type="text" value="hello world" /></div></div><td>
    <td><div><input type="text" value="hello world" /></div><td>
    </tr>
    <tr>
    <td><input type="text" value="tutu" /><td>
    <td><span><input type="text" value="orl" /></span><td>
    </tr>

/* renglones is every <tr> */
$.each( renglones, function() {
        var inputs = $(this).find('input [type=text]').find('input');
        console.info(inputs);
        $(inputs).each(function() {
            console.info($(this).val());
        });
    });
1
  • You are looking for an input that is a child of an input that is a child of an input. Should just be var inputs = $(this).find('input[type=text]'); Commented Sep 30, 2015 at 13:29

2 Answers 2

2

You can just use the :text selector

renglones.each(function () {//assuming renglones is a jQuery object
    var $inputs = $(this).find('input:text');
    $inputs.each(function () {
        console.info($(this).val());
    });
});
Sign up to request clarification or add additional context in comments.

Comments

0

Thanks to Arun P Johny

Final code:

$.each( renglones, function() {
        var $inputs = $(this).find('input:text');
        var encontrado = false;
        $inputs.each(function () {
            if($(this).val().indexOf(texto.toLowerCase()) != -1 || $(this).val().indexOf(texto.toUpperCase()) != -1){
                encontrado = true;
            }
        });
        if(encontrado){
            $(this).show('200');
        }
        else{
            $(this).hide('200');
        }
    });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.