How to run a function after you find something in JQuery

361
November 26, 2016, at 9:10 PM

I have a randomized set of input elements that appear when users select different options on a form. I want to find all the input boxes within a certain div by their classname and then call a function that sets those items to an array of objects. So far I have this:

$('.div-class-name').find('input.input-class-name:textbox')

I'm not sure where to go from here. I know what needs to go into the function once it is called but I don't know how to call it. How do I call a function after a find for all the returned elements?

Thank you in advance.

Answer 1
$('.div-class-name').find('input.input-class-name').each(function(el) {
    //this will run for each matching input
    console.log($(this)); //$(this) is a jquery reference to the element in the list of matching ones
});
Answer 2

Please do it like this:

function load(i){
    $('.div-class-name').find('input.input-class-name:textbox');
}
function makeDrag(){
  //does something here
}
$.when(load(i)).then(makeDrag());
Rent Charter Buses Company
READ ALSO
Display Blob in JSP using img tag

Display Blob in JSP using img tag

I want to build a webapp with user gallery (upload and display photos)In case of upload I'm using an DropZone

524
How to create a menu which slides from left

How to create a menu which slides from left

I want to create a responsive navigation menu which slides from left when button is pushedWhich is the the simplest way to do this?

264
Only show data on html page where javascript date is within last 10 days

Only show data on html page where javascript date is within last 10 days

I have javascript array in which the date coming in is in this format

338
Selenium StaleElementReferenceException error & pageload complete code is not constant. Click on element doesn't work

Selenium StaleElementReferenceException error & pageload complete code is not constant. Click on element doesn't work

I would like to thank the stackoverflow community for all the helpI have been recently trying to handle “StaleElementReferenceException”, but can’t find one solution that fits all

339