So I'm trying to figure out if I can call a function inside of find() as below but I'm not getting anything returned to the console. Is this possible with find() or do I need to find an alternative?
$(".tdInner1").find(".block", function () {
if( $(this).next().hasClass("continuation") ) {
console.log("yes");
} else {
console.log("no");
}
});
jQuery Callback Functions However, with effects, the next line of code can be run even though the effect is not finished. This can create errors. To prevent this, you can create a callback function. A callback function is executed after the current effect is finished.
Callbacks() supports a number of methods including callbacks. add() , callbacks. remove() , callbacks. fire() and callbacks.
jQuery find() Method The find() method returns descendant elements of the selected element. A descendant is a child, grandchild, great-grandchild, and so on. The DOM tree: This method traverse downwards along descendants of DOM elements, all the way down to the last descendant.
The function to which the callback is passed is often referred to as a higher-order function. Conversely, Higher-Order Functions operate on other functions by either taking them as arguments or by returning them.
Sounds like you want .each()
.
$(".tdInner1").find(".block").each(function () {
if( $(this).next().hasClass("continuation") ) {
console.log("yes");
} else {
console.log("no");
}
});
Or maybe .filter()
$(".tdInner1").find(".block").filter(function () {
return $(this).next().hasClass("continuation");
});
You need jQuery
each()
.
$(".tdInner1").find(".block").each( function () {
if( $(this).next().hasClass("continuation") ) {
console.log("yes");
} else {
console.log("no");
}
});
You can read more about jQuery
each()
in Official Documentation
or you can use filter()
var block = $(".tdInner1 .block");
var continuation_is_next = block.next().filter(".continuation").prev();
or like this
var continuation_is_next= $(".tdInner1 .block + .continuation").prev();
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