2017-03-05 12 views
0

が#main DIVテーブルに想定ユーザの内容を表すID foo_userIdは、IDユーザーIDjQueryの複合セレクタ:階層の文字列変数

を持っている私は、可変

<div id="main"> 
    <table id="foo_1234_m"></table> //select this 
    <table id="f0006458_m"></table> 
    <table id="f00_n"></table> 
    <table id="foo_9999_k"></table>   
</div> 


$('div#main>table#foo_1234_m') 
// foo : string , 1234 : variable , m variable 
//////////i'm trying something like : 

var userId='1234'     
var tableID='foo_' + userId   // from this 

$("div#main>table[id^='foo_1234']") // how to make this 
として指定されたIDとはuserId 1234のテーブルを選択しなければなりません

答えて

0

正しいセレクタ構文があるようです。したがって、例と同じ文字列連結を使用してjQueryセレクタを書くことができます。例:

var userId = '1234' 
var tableId = 'foo_' + userId 
var element = $("div#main>table[id^='" + tableId + "']") 
関連する問題