0

I'm creating html elements with a js code and next i should query those elements to connect them with some svg line plugin. Thing is, one is inside the origin element and the other one is not.

what happens with those duplicate ids? is jquery able to find the second one or not?

function paintIds(table){
    $.post('findIds', { 
        chain : table // this is the parameter
    }, function(response) {
        var vec = response.split(","); // the response is a comma separated list of table fields, so i turn it into an array
        vec.forEach(function(c){
            // paint fields on screen
            $('#'+'DW'+table).append('<span class="key" id="sn'+c+'">'+c+'</span>');
        });
        $('#'+'DW'+table).append('<hr>'); put an ht in the end of the list
    });
}

so this happens

operation result

I can have 2 elements called ID_GAL. Then i go and try to connect those elements with another function, but sometimes element ids repeat because they are fields names inside some tables..the ids format goes like #snFIELD_ID

target = $('#sn'+elem).eq(0); 
                                if($('#sn'+elem,'#'+c.replace(/\./g, '')).length == 1) {
                                    console.log('target inside origin')
                                    target= $('#sn'+elem).eq(1); // if i find that one is inside another, then i change my target var to the second
                                }else{
                                    console.log('target is not inside origin')
                                }
                                console.log(target.id + '==> #sn' + elem);
                                var connex = jQuery('#'+c.replace(/\./g, '')).connections({ to: target,'class': 'lineas' });
                                setInterval(function() {
                                      connex.connections('update');
                                    }, 200);

So, thing is, because they are sometimes duplicated i cannot draw my line because the element is inside the origin. In the example DW.DIM GAL > ID_GAL should connect with DW.DIM_ART > ID_GAL

How can i find my second id to connect?

  • 2
    Creating duplicate ids within a document is invalid. Just don’t do it. Make a `data-id` attribute instead or something. – Ry- Sep 02 '19 at 16:12
  • 1
    Possible duplicate of [Can multiple different HTML elements have the same ID if they're different elements?](https://stackoverflow.com/questions/5611963/can-multiple-different-html-elements-have-the-same-id-if-theyre-different-eleme) – Ferdinando Sep 02 '19 at 16:19
  • @Ry, that was the right thing to do. Thanks a lot. – rogerluces Sep 02 '19 at 16:45

0 Answers0