I'm iterating through a series of elements in jQuery (intentionally).
So basically I want something like this, but with the correct syntax:
$(".sonicrow").each(function() {
$(this + 'somediv').css('background-color', 'red');
});
Obviously this is some kind of object/string mishmash. What would the correct syntax be for accessing the specific somediv within the this object?
Thanks, John.
$(".sonicrow").each(function() {
$('somediv', this).css('background-color', 'red');
});
Where the second parameter is the "context" of the selector. Of cause your somediv
have to be .somediv
if it´s a class or #somediv
if it´s an id.
This question is related to How to get the children of the $(this) selector? which also contains this answer
...
$(this).find('somediv').css(...)
...
According to jQuery context selector $(selector, context)
is implemented with $(context).find(selector)
.
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