How to get inner element using parent object without using parent and children jquery function
I am having
<div id=test>
<div class="a"> </div>
<div class="b"> </div>
<div class="c"> </div>
</div>
i have to get third div i.e class name with c using parent obj.
For eg if i do $("#test .c")
i am getting element.
But i am unable to 开发者_StackOverflow中文版get element using parent element as object for eg
var obj = $("#test");
$(obj+".c")
is not giving me output. It is giving me error "Syntax error, unrecognized expression: [object Object]"
Please let me know how it is possible. Thanks in advance.
Search for the element with class c
within the context of the jQuery Object:
var obj = $("#test");
$(".c", obj);
Alternatively you could use:
obj.find(".c");
Or:
$(obj.selector+" .c");
Try
obj.find('.c');
More info on find in the jquery docs
Thats because you combine an object and class selector.
Try
var obj = $("#test");
var objID = obj.attr('id');
$(objID+".c")
Else you could do it with the object like
var obj = $("#test");
$(obj).children('.c')
var objC = $("#test .c");
would select all c's inside test's
精彩评论