i have two divs with the same ids but one has display=none and the other has display=block i want to delete the one with display='none' i am using javascript framework prototype
views:
40answers:
3
+2
A:
You shouldn't have two elements with the same ID. You should use classes.
metrobalderas
2010-04-21 17:41:49
+4
A:
You cannot have two controls with the same ID, it is invalid. You should rewrite your code so the IDs are not the same.
SLC
2010-04-21 17:42:34
i am generating html by ajax so its possible
vakas
2010-04-21 17:43:35
@vakas, regardless of whether it's possible, it's *wrong*. It causes all sorts of problems like the one you're having now. You need to change whatever you're using to generate the html so that it doesn't create two elements with the same ID.
tloflin
2010-04-21 17:46:03
no it's not. If your code adds elements with the same ID than you should fix that as it is invalid.
Pim Jager
2010-04-21 17:46:18
This is indeed "advice" but not an answer, you should vote up @Pim Jager's answer, it is the only one that provides advice and a solution.
2010-04-21 18:05:37
@clarke78 - I think the responders are trying to teach the importance of keeping IDs unique. Arguably this concept is so important that answers to the question posed are moot (and possibly misleading).
Upper Stage
2010-04-21 18:19:11
I think the responders are also getting restless that this is the third near-identical question and the OP has repeatedly ignored the vital “don't reuse IDs” advice.
bobince
2010-04-21 19:15:28
+2
A:
You should switch to giving the divs classes instead of id's. ID's are unique identifiers, thus are unique, and a page should only contain one element per id (an id can not have multiple elements).
If you'd gave the divs classes instead of id's you could do this:
$$(".<your_class_here>").reject(Element.visible).each(Element.remove);
My Prototype is a bit rusty, but I think this should do it.
EDIT: forgot you can't directly filter by CSS properties.
Pim Jager
2010-04-21 18:01:45
m trying thisvar temp=$$(".the_div[display='none']");alert(temp.length);but dis alerts nothing <div id="2" class="the_div" style="display:block"> its testing </div> <div id="2" class="the_div" style="display:none"> its hidden</div>
vakas
2010-04-21 18:35:01
@vakas: Not only are you re-using `id`s, your `id` isn't even a valid name (you can't start with a number). **Seriously, you need to fix this** or you are going to get many strange browser misbehaviours.
bobince
2010-04-21 19:17:01