0

The issue is that I'm trying to select elements with $("a") and its affect only few of the tags in the document, my code

$(document).ready(function() {
    $.ajax({
        type: 'GET',
        url: 'http://localhost/queryProjects',
        success: function(data) {
            var el = $('<div></div>');
            el.html(data);
            var ProjectsObject = $("b:contains('projectName')", el).parent().next();
            var ProjectsArray = $.makeArray(ProjectsObject);
            var DescriptionsObject = $("b:contains('description')", el).parent().next();
            var DescriptionsArray = $.makeArray(DescriptionsObject);
            for (var i = 0; i < ProjectsArray.length; i++) {
                $("tbody:last-child").append('<tr><td>' + (i + 1) + '</td><td><a id="link" href="#">' + ProjectsArray[i].textContent + '</a></td>' + '<td>' + DescriptionsArray[i].textContent + '</td><td style="margin-right=40px;"><a href="#">Run</a></td></tr>');
            }
        }
    });
    $("a#link").click(function() {
        $("table").hide();
    });
});

I have tried with an ID and without, like $("a") and $("a#link").

the AJAX is irrelevant but just so you see how I inject my info to the document.

Thanks!

  • Note you can't repeat ID's in a page. They are unique by definition. Use classes for repeating similar elements – charlietfl Aug 03 '17 at 11:55

1 Answers1

0

Try to move below code inside success. Just after the for loop.

$("a#link").click(function() { $("table").hide(); });
Ayaz
  • 2,111
  • 4
  • 13
  • 16