Click here to Skip to main content
15,888,046 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I have this code:
PHP
function egm() {
        var url = 'district.php';
        var egmHref='egmHref';
        $.getJSON (url, function(data){
            $.each (data, function(index, data){
                $('#tablebody').append('<tr>');
                    $('#tablebody').append('<td>'+data.username+'</td>');
                    $('#tablebody').append('<td>'+data.password+'</td>');
                    $('#tablebody').append('<td>'+data.acclvl+'</td>');
                    $('#tablebody').append('<td>'+ "<a class='" + egmHref +"' href='displayInfo.php?id="+ data.username +"'>View</a>" +'</td>');
                $('#tablebody').append('</tr>');
            });
        });
    }


I have an anchor tag that is appended only at runtime but I'd like to give that anchor an event but i don't know how to call I tried like this $("#egmhref").click().. but did not work anyone teach me how to this... i'm also tried this code but still did not work:

PHP
$("<a />",{
                    text: 'View',
                    id: 'egmHref',
                    href: 'displayInfo.php?user=' + data.username
                }).appendTo('#tablebody td');

Thanks anyone in advanced.....


[edit]SHOUTING removed, Code block added - OriginalGriff[/edit]
Posted
Updated 15-Oct-13 22:06pm
v2
Comments
OriginalGriff 16-Oct-13 4:06am    
DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalisation if you want to be taken seriously.

1 solution

PHP
function egm() {
        var url = 'district.php';
        var egmHref='egmHref';
        $.getJSON (url, function(data){
            $.each (data, function(index, data){
                $('#tablebody').append('<tr>');
                    $('#tablebody').append('<td>'+data.username+'</td>');
                    $('#tablebody').append('<td>'+data.password+'</td>');
                    $('#tablebody').append('<td>'+data.acclvl+'</td>');
                    $('#tablebody').append('<td id="anchor"></td>');
                    $('#anchor').append('<a class='" + egmHref +"' href='displayInfo.php?id="+ data.username +"'>View</a>');
                    $('#tablebody').append('</tr>');
            });
        });
    }



Try this code
 
Share this answer
 
Comments
careLess - Eric 16-Oct-13 8:49am    
hehe sorry.. but i already solved the problem.. but my another problem using this code is that i can't pass the username going to displayInfo.php page for me to query in the database.. how could i do that please provide simple example for this.. thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900