Renumbering divs with Dojo
I found a thread on S.O. similar to what I need here. jQuery removing an element and renumbering remaining elements
The above uses jQuery which we don't use so I'm not sure how to translate this idea of div renumbering to Dojo.
I inherited a massive web project that makes extensive use of Dojo 1.5. I totally dig what I understand of it so far but I have a question.
We have a page with numbered divs tha开发者_开发技巧t I am successfully able to remove and delete the divs from. What I am needing though are divs in sequential order. Here's an example of what I need to re-div
<div id="filter_9_values_2_div">
<div id="filter_9_values_1_div">
<div id="filter_9_values_4_div">
Ideally in my javascript routine where I delete a div, I'd like to rename these in order so they look like this....
<div id="filter_9_values_1_div">
<div id="filter_9_values_2_div">
<div id="filter_9_values_3_div">
Does anyone have any idea how I would pull this off? I know how to successfully add a new div and make it unique but the idea of rewriting the divs is a complete mystery to me. As always many thanks in advance for the help. Janie.
dojo.query('div').forEach(function(el, index){
dojo.attr(el, "id", "filter_9_values_" + (index + 1) + "_div");
});
You might want to use something more specific as a query rather then using just "div" and if you needed more generic ID rather then having the "filter_9_values_..._div" you'd have to use regexp or split to build the string you want but this should give you the basic idea how to iterate over a collection of DOM elements and perform any action on them you could imagine.
精彩评论