jQuery $.each / loop through elements with regex pattern

[javascript]
// Handing to remember for looking through a subset of dom elements..

// The first one loops through to find any dom ID’s STARTING WITH ‘_content’
// (in this case we are hiding the selected elements)

$("div[id^=’_content’]").each(function() {
$(this).hide();
});

// Next one selects ID’s that CONTAIN the text ‘_content’, i.e. mydiv_content

$("div[id*=’_content’]").each(function() {
$(this).hide();
});
[/javascript]

Leave a Reply