Question about select all H3 inside DIV
Wouldn't this work if I want to apply a new class to all H3 tags inside the RelArtik 开发者_C百科div?
$("h3",$("#RelArtik")).addClass("underrubrik");
Thanks.
According to the documentation jQuery should accept a jQuery object as the context so there's no obvious reason why what you've written shouldn't work.
However, it also says that:
$(selector, context)
is equivalent to:
$(context).find(selector)
So you could just try:
$('#RelArtik').find('h3').addClass(...);
which is of course also equivalent to:
$('#RelArtik h3').addClass(...);
however I believe the former .find()
based solution is faster.
it's the same as CSS and would work with a descendant selector
$("#RelArtik h3").addClass("underrubrik");
Alternatively you can just do:
$('#RelArtik h3').addClass('underrubrik');
精彩评论