0

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

2
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by essential
0

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));
   }
}
0

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));
0

Then you'll have to specify the incrementing value.

for (var x = 0; x < 10; x++) {
collapseAll($('div_' + x)); }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.