A T.J Crowder already have said, IDs must be unique within a document. I think you can end up with a very strange effect in your jsTree if there are duplicated IDs, so I would recommend that you do the following.
For each node you're clicking on, store the value of the id attribute in var nodeId
in the example below. The example code will find duplicates of var nodeId
for you. If you find duplicates, then all but the first found node should have the id changed to a unique id. You can do that by appending the value of i
or a random text string to the id.
That's all I can do for you now. If you could provide us with some more detailed information (HTML and your current Javascript code) that would help.
var nodeId = 'the-node-id'; // The id of your node id here.
$('#' + nodeId).each(function() {
var matchingIds = $('[id='+this.id+']'); // May find duplicate ids.
if (matchingIds.length > 1 && matchingIds[0] == this) {
// Duplicates found.
for (i = 0; i < matchingIds.length; i++) {
// Whatever you like to do with the duplicates goes here. I suggest you give them new unique ids.
}
}
});
Update: This is an alternative solution where the duplicated ids are found directly after page load, similiar to T.J Crowder's suggestion.
$('[id]').each(function() { // Selects all elements with ids in the document.
var matchingIds = $('[id='+this.id+']'); // May find duplicate ids.
if (matchingIds.length > 1 && matchingIds[0] == this) {
// Duplicates found.
for (i = 0; i < matchingIds.length; i++) {
// Whatever you like to do with the duplicates goes here. I suggest you give them new unique ids.
}
}
});