It's simple:
$('[id^=tabId][id$=componentId]').each(function(){ var id = $(this).attr('id'); // tabId:someDynamicId:rowId:componentId var list = id.split(':'); console.log(list[0]); // tabId console.log(list[1]); // someDynamicId console.log(list[2]); // rowId console.log(list[3]); // componentId })
Wildcards in jQuery selectors
But I recommend using the right tools for this job. IDs are useful for finding a specific item, but in your case it is better to use one or two classes and data attributes. For example:
<div class="tabs" data-component-id="x" data-tab-id="y">
Then find all the elements of $ ('. Tabs') and use $ (this) .data ('component-id') and $ (this) .data ('tab-id')
$('.tabs').each(function(){ var component_id = $(this).data('component-id'); var tab_id = $(this).data('tab-id'); });
Update:
An example of using this function:
function(tabId,componentId) { $('[id^='+tabId+'][id$='+componentId+']').each(function(){ var id = $(this).attr('id');
Māris Kiseļovs
source share