/    Sign up×
Community /Pin to ProfileBookmark

Create array of items on a page that meet certain criteria

Please forgive me, I’m a bit of a newbie.

I understand how to create an Array and then perform a function on the Array elements that meet a criteria, but I need to create an Array of items that meet a specified criteria (the criteria being the CSS style [B]display:block[/B]).

Once I have that Array, I want to be able to perform a function on the LAST element in the Array. I’m not quite sure how to do that.

I have several DIV elements on a page, which most are hidden using [B]display:none[/B]. When I click a link in a DIV, the next DIV appears. It’s sort of a troubleshooter/checklist.

I want the last visible DIV to be of a style different than the previous DIVs. Also, if I have several DIVs displayed and I go up and click a different option in an earlier step, I need all DIVs after that one to change style back to “display:none”.

Any help would be greatly appreciated.
Thanks.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@postmanauthorApr 28.2006 — Well, I figured out how to perform a function on the LAST item of an array using

[B]

var alldivs = thislink.parentNode.parentNode.childNodes;

alldivs[alldivs.length-1].className = "current";[/B]


But, I still haven't figured out how to create an Array of items that meet a specific criteria.

I'm using [B]childNodes[/B] to get an array of DIVs, but I only want the DIVs that are visible (CSS - "display:block") added to the Array.

Also, is there a way to perform a function on all items of an Array after a certain item number?


For example, I have 10 items in my Array. I want to peform a function on all items after "item[3]".

Again, thanks for any help you can provide.
×

Success!

Help @postman spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...