Reputation: 1362
I have a situation here... I have two div's content1 and content2,each div has a table also... so i get each table like this
$("#content1 table")
or
$("#content2 table")
but I want Like this
var x="#content1" or "#content2"
then something like this
$(x "table")
i.e pass the id to a variable and get the table... any solution?
Upvotes: 1
Views: 81
Reputation: 80
The answer lies in the example you gave itself. Just have to modify it slightly
var x="#content1"; //whatever the name of the parent is
$resulting_table = $(x+" table")
Hope that helps.
Upvotes: 2
Reputation: 205
var x= document.getElementById('content1');
$(x).find("table");
try this one
Upvotes: 4
Reputation: 67207
Try to use the context
i.e] $('selector',context)
,
var x= "#content1";
var table = $('table', x);
And the above code is very much similar to,
var x= "#content1";
var table = $(x).find("table");
Upvotes: 2
Reputation: 148110
You can combine selector using comma by Multiple Selector (“selector1, selector2, selectorN”)
$("#content1 table, #content2 table")
Alternatively you can assign common class to table with #content1 and #content2
$('.common-table-class')
Upvotes: 2