JQuery basic selector usage and non unique element ID -


I'am maintaining a GUI created using JQuery In a section of the GUI, several Tabs can be opened.

When a new tab is opened, the first tab material is made by cloning the device and updating the input field in the divas. / P>

A unique ID based on the new tab tab index, but all other IDs in the clone tab div are similar to the original tab div.

Now, it seems that since the problems arose the ID is not very unique. When an input field works on Firefox 3.6.8, the following works:

  $ ('# tabs-2 #scriptName'). Val (data.name);  

This selects the tab div with the ID tab, and then selects the input field in that device with the id script name and sets its value. Now it does not work on Chrome or Firefox 3.0.19.

DOM Hirari looks like this

   ... & lt; / Div & gt; ... & lt; Div id = "tab-2" & gt; ... & lt; Input id = "scriptname" /> ... & lt; / Div & gt; & Lt; / Div & gt;  

A solution all ID will have to make the content tab to the clone tab unique, but it seems that a ferocious force like a aproach does not require a unique ID The content should be known without the need for a separate ID.

When creating a new tab, cloning the entire box is definitely a crude hack, and more beautiful solutions will have to reuse the same div, but the content must be changed based on the selected tab, but Similarly, it has been created and unfortunately it was developed and later tested using the Firefox browser, where this selector worked.

Edit Pre-Edit

I have got many related questions with those questions which have indicated how to solve it When I put my offline-edited question, but I post this question anyway because good suggestions for its way of solving are always welcome.

Edit

I'm just trying to class, I have a problem though, using labels for some input field attributes Specify a specific ID, especially for the attribute. But it can be solved by excluding that attribute and by making the input field nested element.

IDs are unique identifiers when you present a duplicate ID, you have an invalid on your own The document is.

The best way to go around this is to avoid using any clone that is going to be the ID. Instead, use a "unique" class name to identify the element. Then, when it is cloned, you can run under every DOM in the class. There are many good dome traversal ways of jQuery for this.

Additionally: .children () , .parent () , .parents () , and .siblings () are particularly useful, I want to stay away from the .find () Can not help. .find () may be slow if you are searching multiple nodes from multiple domes since you are creating an interface, so this could be the case.


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -