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");
}
});
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");
}
});
Share
Improve this question
asked Aug 15, 2012 at 18:34
AaronAaron
5502 gold badges6 silver badges23 bronze badges
0
2 Answers
Reset to default 11Sounds 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();