How to fix “mainflipSelectors[i].find” error in jQuery?

53
January 12, 2019, at 4:40 PM

I am building a webpage where I need to display some details about a few people. Each person's details is in the form of a card which goes by this structure:

<div class="mainflip">
    <div class="frontside">
        here goes the "frontside" code
    </div>
    <div class="backside">
        here goes the "backside" code
    </div>
</div>

Now, the details of people are different, so the heights and widths of the "backside"(s) would be different (which, btw, contains the details of the persons). So to get those heights and widths, I wrote the following jQuery:

let mainflipSelectors = $('.mainflip');
for(let i = 0; i < mainflipSelectors.length; i++) {
    let backsideSelector = mainflipSelectors[i].find('.backside');
    let frontsideSelector = mainflipSelectors[i].find('.frontside');
    let backsideWidth = backsideSelector.width();
    let backsideHeight = backsideSelector.height();
    //here goes the rest of the code
}

But the above code throws out the error

Uncaught TypeError: mainflipSelectors[i].find is not a function

I also tried

let backsideSelector = mainflipSelectors[i].children().find('.backside');

That throws

Uncaught TypeError: mainflipSelectors[i].children is not a function

What am I doing wrong?

Answer 1

mainflipSelectors[i] returns the Html element and not the jQuery object.

You can use .eq():

mainflipSelectors.eq(i)

In any case I'd suggest to use .each():

let mainflipSelectors = $('.mainflip');
mainflipSelectors.each(function(idx, ele) {
    var currEle = $(ele);
    let backsideSelector = currEle.find('.backside');
    let frontsideSelector = currEle.find('.frontside');
    let backsideWidth = backsideSelector.width();
    let backsideHeight = backsideSelector.height();
    //here goes the rest of the code
});
READ ALSO
How to use barcode scanner as keyboard input

How to use barcode scanner as keyboard input

I'm using model PowerScan PD1700 (Datalogic brand)I have 2 problems:

62
PM2 cron running every second

PM2 cron running every second

I'm using the --cron flag to run a job every hourThe issue is as soon as I deploy using pm2 deploy

30
Inserting text values from list to a table, created in SQLite database

Inserting text values from list to a table, created in SQLite database

I am creating a database to store all the values from the lists defined in my codeI need the column - Input_CAN_signals to have each element of the list(input_can_signals) as its value

52