Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select each selector using this keyword, when multiple selectors were used?

I don't know much about jquery, So help me to know whether we can use 'this' keyword to select multiple selectors or any alternative to select selectors inside a function like below:

JS

$('.calsub').click(function(){
    var cRow=0,cCol=0;
    var arrA = new Array(arow);
    var arrB = new Array(acol);
    for(cRow=0;cRow<acol;cRow++)
    {
        arrA[cRow] = new Array(acol);
        arrB[cRow] = new Array(acol);
    }
    cRow=cCol=0;.matboxB .ipbox
    $('.matboxA .ipbox, .matboxB .ipbox').each(function(){
        if(this.value){
            arrA[cRow][cCol] = this.value;
            cCol++;
            if(cCol==acol){
                cCol=0;
                cRow++;
            }
        }
        else{
            $(this).css('box-shadow','0 0 1px 2px #ff574b');
        }
        if(cRow==arow){
            return false;
        }
    });cRow=0;cCol=0;
});

HTML

<div class="matboxA" style="max-width: 270px;">
     <input class="ipbox" id="a00" type="text">
     <input class="ipbox" id="a01" type="text">
     <input class="ipbox" id="a02" type="text"> 
</div> 
<div class="matboxB" style="max-width: 270px;"> 
    <input class="ipbox" id="b00" type="text"> 
    <input class="ipbox" id="b01" type="text"> 
    <input class="ipbox" id="b02" type="text"> 
</div>

By Using JS function above I can only select elements inside .matboxA .ipbox. by using this keyword. How can I select elements inside '.matboxB .ipbox'. Please help me.

like image 937
Subramanian Avatar asked Dec 03 '25 10:12

Subramanian


1 Answers

When an element is selected and a procedure follows, jQuery applies the this parameter. To select elements within this scope, one can use the jQuery find() method.

$('.matboxA .ipbox, .matboxB .ipbox').each(function(){

   var innerElement = $(this).find('selector');

};
like image 137
Daniel Avatar answered Dec 04 '25 23:12

Daniel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!