Hi,

I'm currently trying to implement expanding text to links. However, as the links are created dynamically I need to be able to make the DIVs Id-tag 'general' in the script.

So, instead of this:

function pageLoad() {
collapseAll($('myvar_1','myvar_2','myvar_3));
}

I would like something like this:

function pageLoad() {
collapseAll($('myvar_#));
}

But I have no idea how to accomplish that.

Thanks

You can perform loop on the specified element's, like this:

function pageLoad() {
var elem = document.getElementsByTagName("div"); // any reference that you can provide 

   for ( var x = 0; x < elem.length; x++ ) {
   collapseAll($('myvar_'+x));
   }
}

Thanks for your reply, it seems to be the way to go. One problem remains however. As the div-tags id are set dynamically it has to be accounted for in the script.

Hence the tag-name "div" does not exist as it is div1, div2, div3 etc. var elem = document.getElementsByTagName("div"); It needs to be identical with:

for ( var x = 0; x < elem.length; x++ ) {
   collapseAll($('div_'+x));

Then you'll have to specify the incrementing value.

for (var x = 0; x < 10; x++) {
collapseAll($('div_' + x)); }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.